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