ia64/xen-unstable

changeset 13804:f45de0fe8a15

safe_str*() functions check their destination argument is a
character-array type. Fix two bad callers.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Feb 01 13:44:35 2007 +0000 (2007-02-01)
parents 6e81102d29be
children 0a4cbad6752c
files xen/arch/x86/dmi_scan.c xen/common/kexec.c xen/include/xen/string.h
line diff
     1.1 --- a/xen/arch/x86/dmi_scan.c	Thu Feb 01 13:15:03 2007 +0000
     1.2 +++ b/xen/arch/x86/dmi_scan.c	Thu Feb 01 13:44:35 2007 +0000
     1.3 @@ -159,7 +159,7 @@ static void __init dmi_save_ident(struct
     1.4  		return;
     1.5  	dmi_ident[slot] = alloc_bootmem(strlen(p)+1);
     1.6  	if(dmi_ident[slot])
     1.7 -		safe_strcpy(dmi_ident[slot], p);
     1.8 +		strlcpy(dmi_ident[slot], p, strlen(p)+1);
     1.9  	else
    1.10  		printk(KERN_ERR "dmi_save_ident: out of memory.\n");
    1.11  }
     2.1 --- a/xen/common/kexec.c	Thu Feb 01 13:15:03 2007 +0000
     2.2 +++ b/xen/common/kexec.c	Thu Feb 01 13:44:35 2007 +0000
     2.3 @@ -131,7 +131,7 @@ static __init int register_crashdump_tri
     2.4  
     2.5  static void setup_note(Elf_Note *n, const char *name, int type, int descsz)
     2.6  {
     2.7 -    safe_strcpy(ELFNOTE_NAME(n), name);
     2.8 +    strlcpy(ELFNOTE_NAME(n), name, INT_MAX);
     2.9      n->namesz = strlen(name);
    2.10      n->descsz = descsz;
    2.11      n->type = type;
     3.1 --- a/xen/include/xen/string.h	Thu Feb 01 13:15:03 2007 +0000
     3.2 +++ b/xen/include/xen/string.h	Thu Feb 01 13:44:35 2007 +0000
     3.3 @@ -82,8 +82,16 @@ extern void * memchr(const void *,int,__
     3.4  }
     3.5  #endif
     3.6  
     3.7 +#define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[])
     3.8 +
     3.9  /* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */
    3.10 -#define safe_strcpy(d, s) (strlcpy(d, s, sizeof(d)) >= sizeof(d))
    3.11 -#define safe_strcat(d, s) (strlcat(d, s, sizeof(d)) >= sizeof(d))
    3.12 +#define safe_strcpy(d, s) ({                    \
    3.13 +    BUILD_BUG_ON(!is_char_array(d));            \
    3.14 +    (strlcpy(d, s, sizeof(d)) >= sizeof(d));    \
    3.15 +})
    3.16 +#define safe_strcat(d, s) ({                    \
    3.17 +    BUILD_BUG_ON(!is_char_array(d));            \
    3.18 +    (strlcat(d, s, sizeof(d)) >= sizeof(d));    \
    3.19 +})
    3.20  
    3.21  #endif /* _LINUX_STRING_H_ */