Skip to contentSkip to conversation

lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabled

PATCH In review Darwin Rambo 2 participants 2 messages Dec 19, 2013 – Jan 27, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabled

When CONFIG_SYS_VSNPRINTF is enabled, it protects print operations such as sprintf, snprintf, vsnprintf, etc., from buffer overflows. But vsnprintf_internal includes the terminating NULL character in the calculation of number of characters written. This affects sprintf and snprintf return values. Fix this issue by setting pointer 'str' back to the location of the '\0'.

---
 lib/vsprintf.c |    1 +
 1 file changed, 1 insertion(+)
lib/vsprintf.c +1 -0
index 82e5c13..60874da 100644
@@ -750,6 +750,7 @@ repeat:
 		ADDCH(str, '\0');
 		if (str > end)
 			end[-1] = '\0';
+		--str;
 	}
 #else
 	*str = '\0';
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 9 lines · Darwin Rambo

When CONFIG_SYS_VSNPRINTF is enabled, it protects print operations such as sprintf, snprintf, vsnprintf, etc., from buffer overflows. But vsnprintf_internal includes the terminating NULL character in the calculation of number of characters written. This affects sprintf and snprintf return values. Fix this issue by setting pointer 'str' back to the location of the '\0'.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140127/8bf9d960/attachment.pgp>