mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
safe_str*() functions check their destination argument is a
character-array type. Fix two bad callers. Signed-off-by: Keir Fraser <keir@xensource.com>
This commit is contained in:
1 parent
22a3e99d97
commit
6552100e95
3 files changed
+12
-4
No files matched your search
@@ -159,7 +159,7 @@ static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
|
||||
return;
|
||||
dmi_ident[slot] = alloc_bootmem(strlen(p)+1);
|
||||
if(dmi_ident[slot])
|
||||
safe_strcpy(dmi_ident[slot], p);
|
||||
strlcpy(dmi_ident[slot], p, strlen(p)+1);
|
||||
else
|
||||
printk(KERN_ERR "dmi_save_ident: out of memory.\n");
|
||||
}
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ __initcall(register_crashdump_trigger);
|
||||
|
||||
static void setup_note(Elf_Note *n, const char *name, int type, int descsz)
|
||||
{
|
||||
safe_strcpy(ELFNOTE_NAME(n), name);
|
||||
strlcpy(ELFNOTE_NAME(n), name, INT_MAX);
|
||||
n->namesz = strlen(name);
|
||||
n->descsz = descsz;
|
||||
n->type = type;
|
||||
|
||||
@@ -82,8 +82,16 @@ extern void * memchr(const void *,int,__kernel_size_t);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[])
|
||||
|
||||
/* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */
|
||||
#define safe_strcpy(d, s) (strlcpy(d, s, sizeof(d)) >= sizeof(d))
|
||||
#define safe_strcat(d, s) (strlcat(d, s, sizeof(d)) >= sizeof(d))
|
||||
#define safe_strcpy(d, s) ({ \
|
||||
BUILD_BUG_ON(!is_char_array(d)); \
|
||||
(strlcpy(d, s, sizeof(d)) >= sizeof(d)); \
|
||||
})
|
||||
#define safe_strcat(d, s) ({ \
|
||||
BUILD_BUG_ON(!is_char_array(d)); \
|
||||
(strlcat(d, s, sizeof(d)) >= sizeof(d)); \
|
||||
})
|
||||
|
||||
#endif /* _LINUX_STRING_H_ */
|
||||