[coreboot-gerrit] Patch set updated for coreboot: da82222 Remove sprintf

Vladimir Serbinenko (phcoder@gmail.com) gerrit at coreboot.org
Tue Nov 26 17:33:08 CET 2013


Vladimir Serbinenko (phcoder at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4280

-gerrit

commit da822227a7985f6efcccdacc32831038bf63bef5
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Tue Nov 26 02:42:52 2013 +0100

    Remove sprintf
    
    Remove sprintf as if you can't easily use snprintf then you probably
    have buffer overflow.
    
    Change-Id: Ic4570e099a52d743aca938a2bfadb95981adc503
    Signed-off-by: Vladimir Serbinenko <phcoder at gmail.com>
---
 src/arch/x86/boot/acpigen.c |  3 ++-
 src/console/vsprintf.c      | 14 --------------
 src/include/string.h        |  1 -
 3 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/src/arch/x86/boot/acpigen.c b/src/arch/x86/boot/acpigen.c
index 121cb22..6496d75 100644
--- a/src/arch/x86/boot/acpigen.c
+++ b/src/arch/x86/boot/acpigen.c
@@ -274,7 +274,8 @@ int acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len)
 	acpigen_emit_byte(0x83);
 	len = acpigen_write_len_f();
 
-	sprintf(pscope, "\\_PR.CPU%x", (unsigned int) cpuindex);
+	snprintf(pscope, sizeof (pscope),
+		 "\\_PR.CPU%x", (unsigned int) cpuindex);
 	len += acpigen_emit_namestring(pscope);
 	acpigen_emit_byte(cpuindex);
 	acpigen_emit_byte(pblock_addr & 0xff);
diff --git a/src/console/vsprintf.c b/src/console/vsprintf.c
index 3d085e9..99e3dc8 100644
--- a/src/console/vsprintf.c
+++ b/src/console/vsprintf.c
@@ -57,20 +57,6 @@ static int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 	return i;
 }
 
-int sprintf(char *buf, const char *fmt, ...)
-{
-	va_list args;
-	int i;
-
-	va_start(args, fmt);
-	/* A trick: we have at most (size_t)-1 adressable space anyway, so
-	   if we output so much we'll crash anyway.  */
-	i = vsnprintf(buf, -1, fmt, args);
-	va_end(args);
-
-	return i;
-}
-
 int snprintf(char *buf, size_t size, const char *fmt, ...)
 {
 	va_list args;
diff --git a/src/include/string.h b/src/include/string.h
index dc125e1..b4d0268 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -16,7 +16,6 @@ void *memset(void *s, int c, size_t n);
 int memcmp(const void *s1, const void *s2, size_t n);
 void *memchr(const void *s, int c, size_t n);
 #if !defined(__PRE_RAM__)
-int sprintf(char * buf, const char *fmt, ...);
 int snprintf(char * buf, size_t size, const char *fmt, ...);
 #endif
 



More information about the coreboot-gerrit mailing list