Use string bound functions (take #2)
PATCH 2/3 Use string bound functions (take #2)
x86 dependent code.
Signed-off-by Christoph Egger <[email protected]>
xen/arch/x86/cpu/centaur.c +2 -1
@@ -437,7 +437,8 @@ static void __init init_centaur(struct c/* Add L1 data and code cache sizes. */ c->x86_cache_size = (cc>>24 )+(dd>>24 ); } -sprintf ( c->x86_model_id,"WinChip %s" , name ); +snprintf ( c->x86_model_id,sizeof (c->x86_model_id), +"WinChip %s" , name );break ;case 6 :
xen/arch/x86/cpu/common.c +5 -5
@@ -30,9 +30,9 @@ static void default_init(struct cpuinfo_if (c->cpuid_level ==-1 ) {/* No cpuid. It must be an ancient CPU */ if (c->x86 ==4 ) -strcpy (c->x86_model_id,"486" ); +strlcpy (c->x86_model_id,"486" ,sizeof (c->x86_model_id));else if (c->x86 ==3 ) -strcpy (c->x86_model_id,"386" ); +strlcpy (c->x86_model_id,"386" ,sizeof (c->x86_model_id)); } }
@@ -383,11 +383,11 @@ void __devinit identify_cpu(struct cpuinchar *p; p =table_lookup_model (c);if ( p ) -strcpy (c->x86_model_id, p); +strlcpy (c->x86_model_id, p,sizeof (c->x86_model_id));else /* Last resort... */ -sprintf (c->x86_model_id,"%02x/%02x" , - c->x86_vendor, c->x86_model); +snprintf (c->x86_model_id,sizeof (c->x86_model_id), +"%02x/%02x" , c->x86_vendor, c->x86_model); }/* Now the feature flags better reflect actual CPU features! */
xen/arch/x86/cpu/cyrix.c +2 -2
@@ -302,7 +302,7 @@ static void __init init_cyrix(struct cpu dir0_msn =7 ;break ; } -strcpy (buf, Cx86_model[dir0_msn &7 ]); +strlcpy (buf, Cx86_model[dir0_msn &7 ],sizeof (c->x86_model_id));if (p)strcat (buf, p);return ; }
@@ -339,7 +339,7 @@ static void cyrix_identify(struct cpuinfif ( c->x86 ==4 &&test_cyrix_52div () ) {unsigned char dir0, dir1; -strcpy (c->x86_vendor_id,"CyrixInstead" ); +strlcpy (c->x86_vendor_id,"CyrixInstead" ,sizeof (c->x86_vendor_id)); c->x86_vendor =X86_VENDOR_CYRIX ;/* Actually enable cpuid on the older cyrix */
xen/arch/x86/cpu/intel.c +1 -1
@@ -152,7 +152,7 @@ static void __devinit init_intel(struct }if ( p ) -strcpy (c->x86_model_id, p); +strlcpy (c->x86_model_id, p,sizeof (c->x86_model_id)); c->x86_max_cores =num_cpu_cores (c);
xen/arch/x86/dmi_scan.c +1 -1
@@ -159,7 +159,7 @@ static void __init dmi_save_ident(structreturn ; dmi_ident[slot] =alloc_bootmem (strlen (p)+1 );if (dmi_ident[slot]) -strcpy (dmi_ident[slot], p); +strlcpy (dmi_ident[slot], p,sizeof (dmi_ident[slot]));else printk (KERN_ERR "dmi_save_ident: out of memory.\n" ); }
xen/arch/x86/domain_build.c +2 -2
@@ -821,7 +821,7 @@ int construct_dom0(struct domain *d, si->pt_base = vpt_start +2 *PAGE_SIZE * !!IS_COMPAT (d); si->nr_pt_frames = nr_pt_pages; si->mfn_list = vphysmap_start; -sprintf (si->magic,"xen-%i.%i-x86_%d%s" , +snprintf (si->magic,sizeof (si->magic),"xen-%i.%i-x86_%d%s" ,xen_major_version (),xen_minor_version (),elf_64bit (&elf) ?64 :32 , parms.pae ?"p" :"" );
@@ -871,7 +871,7 @@ int construct_dom0(struct domain *d,memset (si->cmd_line,0 ,sizeof (si->cmd_line));if ( cmdline !=NULL ) -strncpy ((char *)si->cmd_line, cmdline,sizeof (si->cmd_line)-1 ); +strlcpy ((char *)si->cmd_line, cmdline,sizeof (si->cmd_line));if (fill_console_start_info ((void *)(si +1 )) ) {
xen/arch/x86/hvm/intercept.c +1 -1
@@ -173,7 +173,7 @@ int hvm_register_savevm(struct domain *dreturn -1 ; } -strncpy (se->idstr, idstr,HVM_SE_IDSTR_LEN ); +strlcpy (se->idstr, idstr,HVM_SE_IDSTR_LEN ); se->instance_id = instance_id; se->version_id = version_id;
xen/arch/x86/oprofile/nmi_int.c +16 -19
@@ -22,6 +22,7 @@#include <asm/regs.h> #include <asm/current.h> #include <xen/delay.h> +#include <xen/string.h> #include "op_counter.h" #include "op_x86_model.h"
@@ -39,7 +40,6 @@ extern int active_id(struct domain *d);extern int active_id (struct domain *d);extern int is_profiled (struct domain *d); -extern size_t strlcpy (char *dest,const char *src,size_t size);static int nmi_callback (struct cpu_user_regs *regs,int cpu)
@@ -276,20 +276,20 @@ static int __init p4_init(char * cpu_typ }#ifndef CONFIG_SMP -strncpy (cpu_type,"i386/p4" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/p4" ,XENOPROF_CPU_TYPE_SIZE ); model = &op_p4_spec;return 1 ;#else switch (smp_num_siblings) {case 1 : -strncpy (cpu_type,"i386/p4" , -XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/p4" , +XENOPROF_CPU_TYPE_SIZE ); model = &op_p4_spec;return 1 ;case 2 : -strncpy (cpu_type,"i386/p4-ht" , -XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/p4-ht" , +XENOPROF_CPU_TYPE_SIZE ); model = &op_p4_ht2_spec;return 1 ; }
@@ -311,17 +311,17 @@ static int __init ppro_init(char *cpu_tyreturn 0 ; }else if (cpu_model ==15 ) -strncpy (cpu_type,"i386/core_2" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/core_2" ,XENOPROF_CPU_TYPE_SIZE );else if (cpu_model ==14 ) -strncpy (cpu_type,"i386/core" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/core" ,XENOPROF_CPU_TYPE_SIZE );else if (cpu_model ==9 ) -strncpy (cpu_type,"i386/p6_mobile" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/p6_mobile" ,XENOPROF_CPU_TYPE_SIZE );else if (cpu_model >5 ) -strncpy (cpu_type,"i386/piii" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/piii" ,XENOPROF_CPU_TYPE_SIZE );else if (cpu_model >2 ) -strncpy (cpu_type,"i386/pii" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/pii" ,XENOPROF_CPU_TYPE_SIZE );else -strncpy (cpu_type,"i386/ppro" ,XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/ppro" ,XENOPROF_CPU_TYPE_SIZE ); model = &op_ppro_spec;return 1 ;
@@ -346,9 +346,6 @@ int nmi_init(int *num_events, int *is_pr } } -/* Make sure string is NULL terminated */ - cpu_type[XENOPROF_CPU_TYPE_SIZE -1 ] =0 ; -switch (vendor) {case X86_VENDOR_AMD :/* Needs to be at least an Athlon (or hammer in 32bit mode) */
@@ -361,15 +358,15 @@ int nmi_init(int *num_events, int *is_prreturn -ENODEV ;case 6 : model = &op_athlon_spec; -strncpy (cpu_type,"i386/athlon" , -XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"i386/athlon" , +XENOPROF_CPU_TYPE_SIZE );break ;case 0xf : model = &op_athlon_spec;/* Actually it could be i386/hammer too, but give user space an consistent name. */ -strncpy (cpu_type,"x86-64/hammer" , -XENOPROF_CPU_TYPE_SIZE -1 ); +strlcpy (cpu_type,"x86-64/hammer" , +XENOPROF_CPU_TYPE_SIZE );break ; }break ;
xen/arch/x86/setup.c +45 -24
95 lines not on this page · raw message
xen/arch/x86/time.c +1 -1
@@ -274,7 +274,7 @@ static char *freq_string(u64 freq)unsigned int x, y; y = (unsigned int )do_div (freq,1000000 ) /1000 ; x = (unsigned int )freq; -sprintf (s,"%u.%03uMHz" , x, y); +snprintf (s,sizeof (s),"%u.%03uMHz" , x, y);return s; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel