Commit ff06b70d authored by Ben Collins's avatar Ben Collins

[PATCH] arch/* strlcpy conversion

Obvious strlcpy conversions in arch/*. In fact, mips and mips64 had an
actual bug in sys_sysmips(). Confirmed with Keith Wesolowski.
parent 15e9369d
......@@ -501,10 +501,9 @@ setup_arch(char **cmdline_p)
boot flags depending on the boot mode, we need some shorthand.
This should do for installation. */
if (strcmp(COMMAND_LINE, "INSTALL") == 0) {
strcpy(command_line, "root=/dev/fd0 load_ramdisk=1");
strlcpy(command_line, "root=/dev/fd0 load_ramdisk=1", sizeof command_line);
} else {
strncpy(command_line, COMMAND_LINE, sizeof command_line);
command_line[sizeof(command_line)-1] = 0;
strlcpy(command_line, COMMAND_LINE, sizeof command_line);
}
strcpy(saved_command_line, command_line);
*cmdline_p = command_line;
......
......@@ -113,8 +113,7 @@ pci_pool_create (const char *name, struct pci_dev *pdev,
if (!(retval = kmalloc (sizeof *retval, SLAB_KERNEL)))
return retval;
strncpy (retval->name, name, sizeof retval->name);
retval->name [sizeof retval->name - 1] = 0;
strlcpy (retval->name, name, sizeof retval->name);
retval->dev = pdev;
INIT_LIST_HEAD (&retval->page_list);
......
......@@ -598,8 +598,7 @@ __tagtable(ATAG_REVISION, parse_tag_revision);
static int __init parse_tag_cmdline(const struct tag *tag)
{
strncpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
default_command_line[COMMAND_LINE_SIZE - 1] = '\0';
strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
return 0;
}
......
......@@ -170,14 +170,12 @@ setup_arch(char **cmdline_p)
*cmdline_p = command_line;
if (romfs_in_flash) {
strncpy(command_line, "root=", COMMAND_LINE_SIZE);
strncpy(command_line+5, CONFIG_ETRAX_ROOT_DEVICE,
COMMAND_LINE_SIZE-5);
strlcpy(command_line, "root=", sizeof(command_line));
strlcat(command_line, CONFIG_ETRAX_ROOT_DEVICE,
sizeof(command_line));
/* Save command line copy for /proc/cmdline */
memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
strlcpy(saved_command_line, command_line, sizeof(saved_command_line));
}
/* give credit for the CRIS port */
......
......@@ -23,10 +23,8 @@ static char clock_override[10] __initdata;
static int __init clock_setup(char* str)
{
if (str) {
strncpy(clock_override, str,10);
clock_override[9] = '\0';
}
if (str)
strlcpy(clock_override, str, sizeof(clock_override));
return 1;
}
__setup("clock=", clock_setup);
......
......@@ -356,8 +356,7 @@ setup_arch (char **cmdline_p)
unw_init();
*cmdline_p = __va(ia64_boot_param->command_line);
strncpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
saved_command_line[COMMAND_LINE_SIZE-1] = '\0'; /* for safety */
strlcpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
efi_init();
......
......@@ -851,14 +851,12 @@ sort_nic_names(lboard_t *lb)
return ;
if ( (tmp1 = strchr(tmp, ';')) ){
strncpy(name, tmp, tmp1-tmp) ;
name[tmp1-tmp] = 0 ;
strlcpy(name, tmp, tmp1-tmp) ;
} else {
strncpy(name, tmp, (sizeof(name) -1)) ;
name[sizeof(name)-1] = 0 ;
strlcpy(name, tmp, (sizeof(name))) ;
}
strcpy(lb->brd_name, name) ;
strlcpy(lb->brd_name, name, sizeof(lb->brd_name)) ;
}
......
......@@ -718,8 +718,7 @@ int elsc_display_mesg(elsc_t *e, char *chr)
for( i = 0; i < numlines; i++ )
{
strncpy( line, chr, L1_DISPLAY_LINE_LENGTH );
line[L1_DISPLAY_LINE_LENGTH] = '\0';
strlcpy( line, chr, sizeof(line) );
/* generally we want to leave the first line of the L1 display
* alone (so the L1 can manipulate it). If you need to be able
......
......@@ -311,14 +311,14 @@ do_intr_reserve_level(cpuid_t cpu, int bit, int resflags, int reserve,
/* Reserve the level and bump the count. */
if (rv != -1) {
if (reserve) {
int maxlen = sizeof(vecblk->info[bit].ii_name) - 1;
int namelen;
vecblk->info[bit].ii_flags |= (II_RESERVE | resflags);
vecblk->info[bit].ii_owner_dev = owner_dev;
/* Copy in the name. */
namelen = name ? strlen(name) : 0;
strncpy(vecblk->info[bit].ii_name, name, min(namelen, maxlen));
vecblk->info[bit].ii_name[maxlen] = '\0';
if (name)
strlcpy(vecblk->info[bit].ii_name, name,
sizeof(vecblk->info[bit].ii_name));
else
vecblk->info[bit].ii_name[0] = '\0';
vecblk->vector_count++;
} else {
vecblk->info[bit].ii_flags = 0; /* Clear all the flags */
......@@ -333,7 +333,6 @@ do_intr_reserve_level(cpuid_t cpu, int bit, int resflags, int reserve,
#if defined(DEBUG)
if (rv >= 0) {
int namelen = name ? strlen(name) : 0;
/* Gather this device - target cpu mapping information
* in a table which can be used later by the idbg "intrmap"
* command
......@@ -347,9 +346,10 @@ do_intr_reserve_level(cpuid_t cpu, int bit, int resflags, int reserve,
p->cpuid = cpu;
p->cnodeid = cpuid_to_cnodeid(cpu);
p->bit = ip * N_INTPEND_BITS + rv;
strncpy(p->intr_name,
name,
min(MAX_NAME,namelen));
if (name)
strlcpy(p->intr_name, name, sizeof(p->intr_name));
else
p->intr_name[0] = '\0';
intr_dev_targ_map_size++;
}
mutex_spinunlock(&intr_dev_targ_map_lock,s);
......
......@@ -787,15 +787,12 @@ sort_nic_names(lboard_t *lb)
if (tmp == NULL)
return ;
if ( (tmp1 = strchr(tmp, ';')) ){
strncpy(name, tmp, tmp1-tmp) ;
name[tmp1-tmp] = 0 ;
} else {
strncpy(name, tmp, (sizeof(name) -1)) ;
name[sizeof(name)-1] = 0 ;
}
if ( (tmp1 = strchr(tmp, ';')) )
strlcpy(name, tmp, tmp1-tmp);
else
strlcpy(name, tmp, (sizeof(name)));
strcpy(lb->brd_name, name) ;
strlcpy(lb->brd_name, name, sizeof(lb->brd_name)) ;
}
......
......@@ -149,7 +149,7 @@ pcibr_slot_startup(devfs_handle_t pcibr_vhdl, pcibr_slot_req_t reqp)
error = pcibr_slot_attach(pcibr_vhdl, slot, D_PCI_HOT_PLUG_ATTACH,
l1_msg, &tmp_up_resp.resp_sub_errno);
strncpy(tmp_up_resp.resp_l1_msg, l1_msg, L1_QSIZE);
strlcpy(tmp_up_resp.resp_l1_msg, l1_msg, L1_QSIZE);
tmp_up_resp.resp_l1_msg[L1_QSIZE] = '\0';
if (COPYOUT(&tmp_up_resp, reqp->req_respp.up, reqp->req_size)) {
......@@ -240,8 +240,8 @@ pcibr_slot_shutdown(devfs_handle_t pcibr_vhdl, pcibr_slot_req_t reqp)
error = pcibr_slot_detach(pcibr_vhdl, slot, D_PCI_HOT_PLUG_DETACH,
l1_msg, &tmp_down_resp.resp_sub_errno);
strncpy(tmp_down_resp.resp_l1_msg, l1_msg, L1_QSIZE);
tmp_down_resp.resp_l1_msg[L1_QSIZE] = '\0';
strlcpy(tmp_down_resp.resp_l1_msg, l1_msg,
sizeof(tmp_down_resp.resp_l1_msg));
shutdown_copyout:
......
......@@ -188,8 +188,7 @@ void __init atari_switches_setup( const char *str, unsigned len )
char *args = switches;
/* copy string to local array, strsep works destructively... */
strncpy( switches, str, len );
switches[len] = 0;
strlcpy( switches, str, sizeof(switches) );
atari_switches = 0;
/* parse the options */
......
......@@ -159,8 +159,7 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
break;
case BI_COMMAND_LINE:
strncpy(m68k_command_line, (const char *)data, CL_SIZE);
m68k_command_line[CL_SIZE-1] = '\0';
strlcpy(m68k_command_line, (const char *)data, sizeof(m68k_command_line));
break;
default:
......@@ -255,8 +254,7 @@ void __init setup_arch(char **cmdline_p)
for( p = *cmdline_p; p && *p; ) {
i = 0;
if (!strncmp( p, "debug=", 6 )) {
strncpy( m68k_debug_device, p+6, sizeof(m68k_debug_device)-1 );
m68k_debug_device[sizeof(m68k_debug_device)-1] = 0;
strlcpy( m68k_debug_device, p+6, sizeof(m68k_debug_device) );
if ((q = strchr( m68k_debug_device, ' ' ))) *q = 0;
i = 1;
}
......
......@@ -147,7 +147,7 @@ int q40_request_irq(unsigned int irq,
irq_tab[irq].handler = handler;
irq_tab[irq].flags = flags;
irq_tab[irq].dev_id = dev_id;
strncpy(irq_tab[irq].devname,devname,DEVNAME_SIZE);
strlcpy(irq_tab[irq].devname,devname,sizeof(irq_tab[irq].devname));
irq_tab[irq].state = 0;
return 0;
}
......
......@@ -1175,7 +1175,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
set_fs(KERNEL_DS);
}
strncpy(psinfo.pr_fname, current->comm, sizeof(psinfo.pr_fname));
strlcpy(psinfo.pr_fname, current->comm, sizeof(psinfo.pr_fname));
notes[2].name = "CORE";
notes[2].type = NT_TASKSTRUCT;
......
......@@ -633,9 +633,8 @@ void __init setup_arch(char **cmdline_p)
panic("Unsupported architecture");
}
strncpy(command_line, arcs_cmdline, sizeof command_line);
command_line[sizeof command_line - 1] = 0;
strcpy(saved_command_line, command_line);
strlcpy(command_line, arcs_cmdline, sizeof command_line);
strlcpy(saved_command_line, command_line, sizeof saved_command_line);
*cmdline_p = command_line;
parse_mem_cmdline();
......
......@@ -64,14 +64,15 @@ sys_sysmips(int cmd, int arg1, int arg2, int arg3)
name = (char *) arg1;
len = strncpy_from_user(nodename, name, sizeof(nodename));
len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
if (len < 0)
return -EFAULT;
nodename[__NEW_UTS_LEN] = '\0';
down_write(&uts_sem);
strncpy(system_utsname.nodename, name, len);
strlcpy(system_utsname.nodename, nodename,
sizeof(system_utsname.nodename));
up_write(&uts_sem);
system_utsname.nodename[len] = '\0';
return 0;
}
......
......@@ -149,9 +149,8 @@ void __init setup_arch(char **cmdline_p)
bootmem_init ();
#endif
strncpy(command_line, arcs_cmdline, CL_SIZE);
memcpy(saved_command_line, command_line, CL_SIZE);
saved_command_line[CL_SIZE-1] = '\0';
strlcpy(command_line, arcs_cmdline, sizeof(command_line));
strlcpy(saved_command_line, command_line, sizeof(saved_command_line));
*cmdline_p = command_line;
......
......@@ -147,14 +147,15 @@ _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
name = (char *) arg1;
len = strncpy_from_user(nodename, name, sizeof(nodename));
len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
if (len < 0)
return -EFAULT;
nodename[__NEW_UTS_LEN] = '\0';
down_write(&uts_sem);
strncpy(system_utsname.nodename, name, len);
strlcpy(system_utsname.nodename, nodename,
sizeof(system_utsname.nodename));
up_write(&uts_sem);
system_utsname.nodename[len] = '\0';
return 0;
}
......
......@@ -398,7 +398,7 @@ alloc_pa_dev(unsigned long hpa, struct hardware_path *mod_path)
dev->hpa = hpa;
name = parisc_hardware_description(&dev->id);
if (name) {
strncpy(dev->name, name, sizeof(dev->name)-1);
strlcpy(dev->name, name, sizeof(dev->name));
}
return dev;
......@@ -601,7 +601,7 @@ static void parisc_generic_device_register_recursive( struct parisc_device *dev
ndev = ndev->parent) {
snprintf(tmp2, sizeof(tmp2), "%d:%s",
ndev->hw_path, tmp1);
strncpy(tmp1, tmp2, sizeof(tmp1));
strlcpy(tmp1, tmp2, sizeof(tmp1));
}
}
......
......@@ -1654,8 +1654,8 @@ static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
switch (cmd) {
case SOUND_MIXER_INFO: {
mixer_info info;
strncpy(info.id, "CS4218_TDM", sizeof(info.id));
strncpy(info.name, "CS4218_TDM", sizeof(info.name));
strlcpy(info.id, "CS4218_TDM", sizeof(info.id));
strlcpy(info.name, "CS4218_TDM", sizeof(info.name));
info.name[sizeof(info.name)-1] = 0;
info.modify_counter = mixer.modify_counter;
if (copy_to_user((int *)arg, &info, sizeof(info)))
......
......@@ -59,8 +59,7 @@ void __init parse_bootinfo(const struct bi_record *record)
break;
case BI_COMMAND_LINE:
strncpy(cmd_line, (const char *)data, CL_SIZE);
cmd_line[CL_SIZE-1] = '\0';
strlcpy(cmd_line, (const char *)data, sizeof(cmd_line));
break;
default:
......
......@@ -403,14 +403,14 @@ platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
* are used for initrd_start and initrd_size,
* otherwise they contain 0xdeadbeef.
*/
cmd_line[0] = 0;
if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
cmd_line[0] = 0;
strncpy(cmd_line, (char *)r3 + KERNELBASE,
strlcpy(cmd_line, (char *)r3 + KERNELBASE,
sizeof(cmd_line));
} else if (boot_infos != 0) {
/* booted by BootX - check for ramdisk */
if (boot_infos->kernelParamsOffset != 0)
strncpy(cmd_line, (char *) boot_infos
strlcpy(cmd_line, (char *) boot_infos
+ boot_infos->kernelParamsOffset,
sizeof(cmd_line));
#ifdef CONFIG_BLK_DEV_INITRD
......@@ -439,12 +439,10 @@ platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
if (chosen != NULL) {
p = get_property(chosen, "bootargs", NULL);
if (p && *p) {
cmd_line[0] = 0;
strncpy(cmd_line, p, sizeof(cmd_line));
strlcpy(cmd_line, p, sizeof(cmd_line));
}
}
}
cmd_line[sizeof(cmd_line) - 1] = 0;
#ifdef CONFIG_ADB
if (strstr(cmd_line, "adb_sync")) {
extern int __adb_probe_sync;
......
......@@ -130,8 +130,7 @@ void __init apus_setup_arch(void)
for( p = cmd_line; p && *p; ) {
i = 0;
if (!strncmp( p, "debug=", 6 )) {
strncpy( debug_device, p+6, sizeof(debug_device)-1 );
debug_device[sizeof(debug_device)-1] = 0;
strlcpy( debug_device, p+6, sizeof(debug_device) );
if ((q = strchr( debug_device, ' ' ))) *q = 0;
i = 1;
} else if (!strncmp( p, "60nsram", 7 )) {
......
......@@ -330,7 +330,7 @@ pmac_cpufreq_setup(void)
driver->setpolicy = &pmac_cpufreq_setpolicy;
driver->init = NULL;
driver->exit = NULL;
strncpy(driver->name, "powermac", CPUFREQ_NAME_LEN);
strlcpy(driver->name, "powermac", sizeof(driver->name));
driver->policy[0].cpu = 0;
driver->policy[0].cpuinfo.transition_latency = CPUFREQ_ETERNAL;
......
......@@ -104,9 +104,9 @@ zx4500_setup_arch(void)
#endif
/* Get boot string from flash */
strncpy(boot_string,
strlcpy(boot_string,
(char *)ZX4500_BOOT_STRING_ADDR,
ZX4500_BOOT_STRING_LEN);
sizeof(boot_string));
boot_string[ZX4500_BOOT_STRING_LEN] = '\0';
/* Can be delimited by 0xff */
......
......@@ -365,16 +365,15 @@ void parse_cmd_line(unsigned long r3, unsigned long r4, unsigned long r5,
cmd_line[0] = 0;
#ifdef CONFIG_CMDLINE
strcpy(cmd_line, CONFIG_CMDLINE);
strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
#endif /* CONFIG_CMDLINE */
chosen = find_devices("chosen");
if (chosen != NULL) {
p = get_property(chosen, "bootargs", NULL);
if (p != NULL && p[0] != 0)
strncpy(cmd_line, p, sizeof(cmd_line));
strlcpy(cmd_line, p, sizeof(cmd_line));
}
cmd_line[sizeof(cmd_line) - 1] = 0;
/* Look for mem= option on command line */
if (strstr(cmd_line, "mem=")) {
......
......@@ -208,8 +208,7 @@ static debug_info_t* debug_info_alloc(char *name, int page_order,
rc->level = DEBUG_DEFAULT_LEVEL;
rc->buf_size = buf_size;
rc->entry_size = sizeof(debug_entry_t) + buf_size;
strncpy(rc->name, name, MIN(strlen(name), (DEBUG_MAX_PROCF_LEN - 1)));
rc->name[MIN(strlen(name), (DEBUG_MAX_PROCF_LEN - 1))] = 0;
strlcpy(rc->name, name, sizeof(rc->name));
memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
#ifdef CONFIG_PROC_FS
memset(rc->proc_entries, 0 ,DEBUG_MAX_VIEWS *
......
......@@ -179,8 +179,7 @@ static void *_sparc_alloc_io(unsigned int busno, unsigned long phys,
tack += sizeof (struct resource);
}
strncpy(tack, name, XNMLN);
tack[XNMLN] = 0;
strlcpy(tack, name, XNMLN+1);
res->name = tack;
va = _sparc_ioremap(res, busno, phys, size);
......
......@@ -738,8 +738,8 @@ static int sunos_nfs_mount(char *dir_name, int linux_flags, void *data)
if(IS_ERR(the_name))
return PTR_ERR(the_name);
strncpy (linux_nfs_mount.hostname, the_name, 254);
linux_nfs_mount.hostname [255] = 0;
strlcpy(linux_nfs_mount.hostname, the_name,
sizeof(linux_nfs_mount.hostname));
putname (the_name);
return do_mount ("", dir_name, "nfs", linux_flags, &linux_nfs_mount);
......
......@@ -52,7 +52,7 @@ prom_getbootargs(void)
* V3 PROM cannot supply as with more than 128 bytes
* of an argument. But a smart bootstrap loader can.
*/
strncpy(barg_buf, *romvec->pv_v2bootargs.bootargs, BARG_LEN-1);
strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf));
break;
default:
break;
......
......@@ -704,8 +704,8 @@ static int sunos_nfs_mount(char *dir_name, int linux_flags, void *data)
if(IS_ERR(the_name))
return PTR_ERR(the_name);
strncpy (linux_nfs_mount.hostname, the_name, 254);
linux_nfs_mount.hostname [255] = 0;
strlcpy(linux_nfs_mount.hostname, the_name,
sizeof(linux_nfs_mount.hostname));
putname (the_name);
return do_mount ("", dir_name, "nfs", linux_flags, &linux_nfs_mount);
......
......@@ -563,9 +563,7 @@ char *add_xterm_umid(char *base)
return(base);
}
strncpy(title, base, len);
len -= strlen(title);
snprintf(&title[strlen(title)], len, " (%s)", umid);
snprintf(title, len, "%s (%s)", base, umid);
return(title);
}
......
......@@ -45,8 +45,7 @@ static int __init set_umid(char *name, int is_random)
if(strlen(name) > UMID_LEN - 1)
printk("Unique machine name is being truncated to %s "
"characters\n", UMID_LEN);
strncpy(umid, name, UMID_LEN - 1);
umid[UMID_LEN - 1] = '\0';
strlcpy(umid, name, sizeof(umid));
umid_is_random = is_random;
umid_inited = 1;
......@@ -222,7 +221,7 @@ static int __init make_uml_dir(void)
"$HOME\n");
exit(1);
}
strncpy(dir, home, sizeof(dir));
strlcpy(dir, home, sizeof(dir));
uml_dir++;
}
len = strlen(dir);
......@@ -251,8 +250,7 @@ static int __init make_umid(void)
int fd, err;
char tmp[strlen(uml_dir) + UMID_LEN + 1];
strncpy(tmp, uml_dir, sizeof(tmp) - 1);
tmp[sizeof(tmp) - 1] = '\0';
strlcpy(tmp, uml_dir, sizeof(tmp));
if(*umid == 0){
strcat(tmp, "XXXXXX");
......
......@@ -143,7 +143,7 @@ static int tuntap_open(void *data)
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP;
strncpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name) - 1);
strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
printk("TUNSETIFF failed, errno = %d", errno);
close(pri->fd);
......
......@@ -468,8 +468,7 @@ static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
if (!dev)
return -ENODEV;
strncpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name)-1);
ifr32.ifr_name[sizeof(ifr32.ifr_name)-1] = 0;
strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
dev_put(dev);
err = copy_to_user((struct ifreq32 *)arg, &ifr32, sizeof(struct ifreq32));
......
......@@ -170,8 +170,7 @@ int __init setup_early_printk(char *opt)
if (early_console_initialized)
return -1;
strncpy(buf,opt,256);
buf[255] = 0;
strlcpy(buf,opt,sizeof(buf));
space = strchr(buf, ' ');
if (space)
*space = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment