Change uses of sprintf to snprintf

git-svn-id: svn://coreboot.org/openbios/openbios-devel@277 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Blue Swirl
2008-11-30 13:44:38 +00:00
parent ad4a1b3af0
commit c77259ec3a
18 changed files with 45 additions and 38 deletions

View File

@@ -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++ )

View File

@@ -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++ ) {

View File

@@ -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 ) {

View File

@@ -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++ ) {

View File

@@ -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++ ) {

View File

@@ -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);

View File

@@ -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)

View File

@@ -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++ )

View File

@@ -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)

View File

@@ -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++ )

View File

@@ -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);

View File

@@ -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++ )

View File

@@ -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);

View File

@@ -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;
@@ -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");

View File

@@ -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)++;
}

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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