public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabled
@ 2013-12-19 23:14 Darwin Rambo
  2014-01-27 14:53 ` [U-Boot] " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Darwin Rambo @ 2013-12-19 23:14 UTC (permalink / raw)
  To: u-boot

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'.

Signed-off-by: Darwin Rambo <drambo@broadcom.com>
Reviewed-by: Steve Rae <srae@broadcom.com>
---
 lib/vsprintf.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 82e5c13..60874da 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -750,6 +750,7 @@ repeat:
 		ADDCH(str, '\0');
 		if (str > end)
 			end[-1] = '\0';
+		--str;
 	}
 #else
 	*str = '\0';
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-27 14:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-19 23:14 [U-Boot] [PATCH] lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabled Darwin Rambo
2014-01-27 14:53 ` [U-Boot] " Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox