diff mbox

[U-Boot,x86,zboot] Change printf to puts to avoid a buffer overflow

Message ID 1320744101-32666-1-git-send-email-gabeblack@chromium.org
State Superseded
Delegated to: Graeme Russ
Headers show

Commit Message

Gabe Black Nov. 8, 2011, 9:21 a.m. UTC
printf as currently implemented in u-boot has a problem where it can
overflow an internal buffer if it prints an expanded string that's too
long. Our command lines are long enough to cause this problem. A fix
should be coming, but in the mean time this change replaces a problematic
printf with a few calls to puts that have the same effect. This may perform
slightly better because it should avoid a copy and scanning for format
specifiers. The amount of time it actually takes up is very tiny relative
to everything else so in practice that's probably irrelevant.

Signed-off-by: Gabe Black <gabeblack@chromium.org>
---
 arch/x86/lib/zimage.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Comments

Mike Frysinger Nov. 8, 2011, 1:48 p.m. UTC | #1
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
Graeme Russ Nov. 12, 2011, 10:22 a.m. UTC | #2
Hi Gabe,

On 08/11/11 20:21, Gabe Black wrote:
> printf as currently implemented in u-boot has a problem where it can
> overflow an internal buffer if it prints an expanded string that's too
> long. Our command lines are long enough to cause this problem. A fix
> should be coming, but in the mean time this change replaces a problematic
> printf with a few calls to puts that have the same effect. This may perform
> slightly better because it should avoid a copy and scanning for format
> specifiers. The amount of time it actually takes up is very tiny relative
> to everything else so in practice that's probably irrelevant.
> 
> Signed-off-by: Gabe Black <gabeblack@chromium.org>
> ---
>  arch/x86/lib/zimage.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)

Can you please rebase against u-boot-x86/master and re-submit

While you're at it, please change tag to 'x86:' style

Thanks,

Graeme
diff mbox

Patch

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index d2dd6fd..a48ae6c 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -78,7 +78,9 @@  static void build_command_line(char *command_line, int auto_boot)
 	}
 
 
-	printf("Kernel command line: \"%s\"\n", command_line);
+	puts("Kernel command line: \"");
+	puts(command_line);
+	puts("\"\n");
 }
 
 void *load_zimage(char *image, unsigned long kernel_size,