From c77259ec3a60a303cb3e37dd409b0b561eaf7677 Mon Sep 17 00:00:00 2001 From: Blue Swirl Date: Sun, 30 Nov 2008 13:44:38 +0000 Subject: [PATCH] Change uses of sprintf to snprintf git-svn-id: svn://coreboot.org/openbios/openbios-devel@277 f158a5a8-5612-0410-a976-696ce0be7e32 --- arch/amd64/lib.c | 4 ++-- arch/ppc/briq/briq.c | 4 ++-- arch/ppc/mol/main.c | 3 ++- arch/ppc/mol/mol.c | 4 ++-- arch/ppc/pearpc/pearpc.c | 4 ++-- arch/ppc/qemu/qemu.c | 6 +++--- arch/sparc32/boot.c | 2 +- arch/sparc32/lib.c | 4 ++-- arch/sparc64/boot.c | 2 +- arch/sparc64/lib.c | 4 ++-- arch/sparc64/openbios.c | 4 ++-- arch/x86/lib.c | 4 ++-- drivers/adb.c | 4 ++-- drivers/cuda.c | 8 ++++---- drivers/esp.c | 10 ++++++---- drivers/ide.c | 5 +++-- drivers/obio.c | 3 ++- drivers/pci.c | 8 +++++--- 18 files changed, 45 insertions(+), 38 deletions(-) diff --git a/arch/amd64/lib.c b/arch/amd64/lib.c index 88cd79e..aae9853 100644 --- a/arch/amd64/lib.c +++ b/arch/amd64/lib.c @@ -19,12 +19,12 @@ */ int printk( const char *fmt, ... ) { - char *p, buf[512]; /* XXX: no buffer overflow protection... */ + char *p, buf[512]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) diff --git a/arch/ppc/briq/briq.c b/arch/ppc/briq/briq.c index dbd1706..17087b4 100644 --- a/arch/ppc/briq/briq.c +++ b/arch/ppc/briq/briq.c @@ -62,12 +62,12 @@ static int do_indent; int printk( const char *fmt, ... ) { - char *p, buf[1024]; /* XXX: no buffer overflow protection... */ + char *p, buf[1024]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vnsprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) { diff --git a/arch/ppc/mol/main.c b/arch/ppc/mol/main.c index 8b39ade..062af83 100644 --- a/arch/ppc/mol/main.c +++ b/arch/ppc/mol/main.c @@ -300,7 +300,8 @@ newworld_startup( void ) continue; for( j=0; !entry && j<32; j++ ) { - sprintf( spec, "%s/disk@%x:%d", path, i, j ); + snprintf( spec, sizeof(spec), "%s/disk@%x:%d", + path, i, j ); entry = newworld_load( path, spec, (!type || type==2) ); } if( entry ) { diff --git a/arch/ppc/mol/mol.c b/arch/ppc/mol/mol.c index cfc657c..e431ecf 100644 --- a/arch/ppc/mol/mol.c +++ b/arch/ppc/mol/mol.c @@ -57,12 +57,12 @@ static int do_indent; int printk( const char *fmt, ... ) { - char *p, buf[1024]; /* XXX: no buffer overflow protection... */ + char *p, buf[1024]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vnsprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) { diff --git a/arch/ppc/pearpc/pearpc.c b/arch/ppc/pearpc/pearpc.c index 4bf7e94..5c181c2 100644 --- a/arch/ppc/pearpc/pearpc.c +++ b/arch/ppc/pearpc/pearpc.c @@ -64,12 +64,12 @@ static int do_indent; int printk( const char *fmt, ... ) { - char *p, buf[1024]; /* XXX: no buffer overflow protection... */ + char *p, buf[1024]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) { diff --git a/arch/ppc/qemu/qemu.c b/arch/ppc/qemu/qemu.c index b0c2dd5..ee45bdc 100644 --- a/arch/ppc/qemu/qemu.c +++ b/arch/ppc/qemu/qemu.c @@ -62,12 +62,12 @@ static int do_indent; int printk( const char *fmt, ... ) { - char *p, buf[1024]; /* XXX: no buffer overflow protection... */ + char *p, buf[1024]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) { @@ -105,7 +105,7 @@ void macio_nvram_init(char *path, uint32_t addr) char buf[64]; nvram = (char*)addr + IO_NVRAM_OFFSET; - sprintf(buf, "%s/nvram", path); + snprintf(buf, sizeof(buf), "%s/nvram", path); nvram_init(buf); dnode = find_dev(buf); set_int_property(dnode, "#bytes", IO_NVRAM_SIZE >> 4); diff --git a/arch/sparc32/boot.c b/arch/sparc32/boot.c index bf14960..08e3f83 100644 --- a/arch/sparc32/boot.c +++ b/arch/sparc32/boot.c @@ -107,7 +107,7 @@ void boot(void) if (linux_load(&sys_info, path, param) == LOADER_NOT_SUPPORT) if (aout_load(&sys_info, path, romvec) == LOADER_NOT_SUPPORT) { - sprintf(altpath, "%s:d", path); + snprintf(altpath, sizeof(altpath), "%s:d", path); if (elf_load(&sys_info, altpath, param, romvec) == LOADER_NOT_SUPPORT) diff --git a/arch/sparc32/lib.c b/arch/sparc32/lib.c index 88faa98..3f212f8 100644 --- a/arch/sparc32/lib.c +++ b/arch/sparc32/lib.c @@ -19,12 +19,12 @@ */ int printk( const char *fmt, ... ) { - char *p, buf[512]; /* XXX: no buffer overflow protection... */ + char *p, buf[512]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) diff --git a/arch/sparc64/boot.c b/arch/sparc64/boot.c index 1cdb58b..17aef76 100644 --- a/arch/sparc64/boot.c +++ b/arch/sparc64/boot.c @@ -88,7 +88,7 @@ void boot(void) if (aout_load(&sys_info, path) == LOADER_NOT_SUPPORT) if (fcode_load(path) == LOADER_NOT_SUPPORT) { - sprintf(altpath, "%s:d", path); + snprintf(altpath, sizeof(altpath), "%s:d", path); if (elf_load(&sys_info, altpath, param) == LOADER_NOT_SUPPORT) diff --git a/arch/sparc64/lib.c b/arch/sparc64/lib.c index 67b30d0..4fd073e 100644 --- a/arch/sparc64/lib.c +++ b/arch/sparc64/lib.c @@ -19,12 +19,12 @@ */ int printk( const char *fmt, ... ) { - char *p, buf[512]; /* XXX: no buffer overflow protection... */ + char *p, buf[512]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c index ab48169..b0078c1 100644 --- a/arch/sparc64/openbios.c +++ b/arch/sparc64/openbios.c @@ -432,7 +432,7 @@ static void cpu_generic_init(const struct cpudef *cpu) fword("finish-device"); // MMU node - sprintf(nodebuff, "/%s", cpu->name); + snprintf(nodebuff, sizeof(nodebuff), "/%s", cpu->name); push_str(nodebuff); fword("find-device"); @@ -443,7 +443,7 @@ static void cpu_generic_init(const struct cpudef *cpu) fword("finish-device"); - sprintf(nodebuff, "/%s/mmu", cpu->name); + snprintf(nodebuff, sizeof(nodebuff), "/%s/mmu", cpu->name); REGISTER_NODE_METHODS(mmu, nodebuff); diff --git a/arch/x86/lib.c b/arch/x86/lib.c index 88cd79e..aae9853 100644 --- a/arch/x86/lib.c +++ b/arch/x86/lib.c @@ -19,12 +19,12 @@ */ int printk( const char *fmt, ... ) { - char *p, buf[512]; /* XXX: no buffer overflow protection... */ + char *p, buf[512]; va_list args; int i; va_start(args, fmt); - i=vsprintf(buf,fmt,args); + i = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); for( p=buf; *p; p++ ) diff --git a/drivers/adb.c b/drivers/adb.c index 393e02f..c7462d2 100644 --- a/drivers/adb.c +++ b/drivers/adb.c @@ -494,7 +494,7 @@ void *adb_kbd_new (char *path, void *private) my_adb_dev = dev; } - sprintf(buf, "%s/keyboard", path); + snprintf(buf, sizeof(buf), "%s/keyboard", path); REGISTER_NAMED_NODE( keyboard, buf); ph = find_dev(buf); @@ -551,7 +551,7 @@ void adb_mouse_new (char *path, void *private) phandle_t ph, aliases; adb_dev_t *dev = private; - sprintf(buf, "%s/mouse", path); + snprintf(buf, sizeof(buf), "%s/mouse", path); REGISTER_NAMED_NODE( mouse, buf); ph = find_dev(buf); diff --git a/drivers/cuda.c b/drivers/cuda.c index 5473387..0ccc6d1 100644 --- a/drivers/cuda.c +++ b/drivers/cuda.c @@ -227,7 +227,7 @@ rtc_init(char *path) phandle_t ph, aliases; char buf[64]; - sprintf(buf, "%s/rtc", path); + snprintf(buf, sizeof(buf), "%s/rtc", path); REGISTER_NAMED_NODE(rtc, buf); ph = find_dev(buf); @@ -250,7 +250,7 @@ cuda_t *cuda_init (char *path, uint32_t base) if (cuda == NULL) return NULL; - sprintf(buf, "%s/via-cuda", path); + snprintf(buf, sizeof(buf), "%s/via-cuda", path); REGISTER_NAMED_NODE(ob_cuda, buf); cuda->base = base; @@ -323,7 +323,7 @@ adb_bus_t *adb_bus_new (void *host, * */ int adb_bus_init (char *path, adb_bus_t *bus) { - char buf[64]; + char buf[64]; uint8_t buffer[ADB_BUF_SIZE]; uint8_t adb_addresses[16] = { 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, 0, }; @@ -332,7 +332,7 @@ int adb_bus_init (char *path, adb_bus_t *bus) int reloc = 0, next_free = 7; int keep; - sprintf(buf, "%s/adb", path); + snprintf(buf, sizeof(buf), "%s/adb", path); REGISTER_NAMED_NODE( adb, buf); /* Reset the bus */ // ADB_DPRINTF("\n"); diff --git a/drivers/esp.c b/drivers/esp.c index 4660046..f3ef861 100644 --- a/drivers/esp.c +++ b/drivers/esp.c @@ -507,7 +507,8 @@ ob_esp_init(unsigned int slot, uint64_t base, unsigned long espoffset, push_str("reg"); fword("property"); fword("finish-device"); - sprintf(nodebuff, "/iommu/sbus/espdma/esp/sd@%d,0", id); + snprintf(nodebuff, sizeof(nodebuff), "/iommu/sbus/espdma/esp/sd@%d,0", + id); REGISTER_NODE_METHODS(ob_sd, nodebuff); if (esp->sd[id].media == TYPE_ROM) { counter_ptr = &cdcount; @@ -517,11 +518,12 @@ ob_esp_init(unsigned int slot, uint64_t base, unsigned long espoffset, if (*counter_ptr == 0) { add_alias(nodebuff, esp->sd[id].media_str); } - sprintf(aliasbuff, "%s%d", esp->sd[id].media_str, *counter_ptr); + snprintf(aliasbuff, sizeof(aliasbuff), "%s%d", esp->sd[id].media_str, + *counter_ptr); add_alias(nodebuff, aliasbuff); - sprintf(aliasbuff, "sd(0,%d,0)", id); + snprintf(aliasbuff, sizeof(aliasbuff), "sd(0,%d,0)", id); add_alias(nodebuff, aliasbuff); - sprintf(aliasbuff, "sd(0,%d,0)@0,0", id); + snprintf(aliasbuff, sizeof(aliasbuff), "sd(0,%d,0)@0,0", id); add_alias(nodebuff, aliasbuff); (*counter_ptr)++; } diff --git a/drivers/ide.c b/drivers/ide.c index 93ea925..7f023a0 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -1330,7 +1330,7 @@ int ob_ide_init(void) ob_ide_identify_drives(chan); - sprintf(nodebuff, nodetemp_chan, i); + snprintf(nodebuff, sizeof(nodebuff), nodetemp_chan, i); REGISTER_NAMED_NODE(ob_ide_ctrl, nodebuff); printk("ide%d: [io ports 0x%x-0x%x,0x%x]\n", i, chan->io_regs[0], chan->io_regs[0] + 7, chan->io_regs[8]); @@ -1357,7 +1357,8 @@ int ob_ide_init(void) break; } printk("%s]: %s\n", media, drive->model); - sprintf(nodebuff, nodetemp, i, media); + snprintf(nodebuff, sizeof(nodebuff), nodetemp, i, + media); REGISTER_NAMED_NODE(ob_ide, nodebuff); dnode=find_dev(nodebuff); set_int_property(dnode, "reg", j); diff --git a/drivers/obio.c b/drivers/obio.c index da59607..0ffde13 100644 --- a/drivers/obio.c +++ b/drivers/obio.c @@ -275,7 +275,8 @@ ob_zs_init(uint64_t base, uint64_t offset, int intr, int slave, int keyboard) fword("finish-device"); - sprintf(nodebuff, "/obio/zs@0,%x", (int)offset & 0xffffffff); + snprintf(nodebuff, sizeof(nodebuff), "/obio/zs@0,%x", + (int)offset & 0xffffffff); if (keyboard) { REGISTER_NODE_METHODS(zs_keyboard, nodebuff); } else { diff --git a/drivers/pci.c b/drivers/pci.c index b9b8b5e..5e39ed7 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -1098,7 +1098,7 @@ static int macio_config_cb (const pci_config_t *config) phandle_t ph; cell props[2]; - sprintf(buf, "%s/interrupt-controller", config->path); + snprintf(buf, sizeof(buf), "%s/interrupt-controller", config->path); REGISTER_NAMED_NODE(ob_pci_node, buf); ph = find_dev(buf); @@ -1505,9 +1505,11 @@ static void ob_scan_pci_bus(int bus, unsigned long *mem_base, dbus=get_cur_dev(); if (pci_dev == NULL || pci_dev->name == NULL) - sprintf(config.path, "%s/pci%x,%x", path, vid, did); + snprintf(config.path, sizeof(config.path), + "%s/pci%x,%x", path, vid, did); else - sprintf(config.path, "%s/%s", path, pci_dev->name); + snprintf(config.path, sizeof(config.path), + "%s/%s", path, pci_dev->name); #ifdef CONFIG_DEBUG_PCI printk("%s - ", config.path); #endif