aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/libelf
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-29 14:59:42 +0000
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-29 14:59:42 +0000
commita9d66ce46044f8437a39aca8967a526553ac0c6e (patch)
tree547fa39b007d124a64a35a9f1ee6a259d8b5a0da /xen/common/libelf
parent80777c3aae7011f0230d5b023fffeda51c4bb136 (diff)
downloadxen-a9d66ce46044f8437a39aca8967a526553ac0c6e.tar.gz
xen-a9d66ce46044f8437a39aca8967a526553ac0c6e.tar.bz2
xen-a9d66ce46044f8437a39aca8967a526553ac0c6e.zip
Remove uses of strcpy and strncpy from common and x86 code.
Retain safe_strcpy(). It can hide the third argument to strlcpy() in most cases. Based on patches from Christoph Egger <Christoph.Egger@amd.com> Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'xen/common/libelf')
-rw-r--r--xen/common/libelf/libelf-dominfo.c16
-rw-r--r--xen/common/libelf/libelf-private.h13
2 files changed, 12 insertions, 17 deletions
diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index c353acde16..9d45b8ae21 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -128,16 +128,16 @@ int elf_xen_parse_note(struct elf_binary *elf,
switch (type)
{
case XEN_ELFNOTE_LOADER:
- elf_strlcpy(parms->loader, str, sizeof(parms->loader));
+ safe_strcpy(parms->loader, str);
break;
case XEN_ELFNOTE_GUEST_OS:
- elf_strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
+ safe_strcpy(parms->guest_os, str);
break;
case XEN_ELFNOTE_GUEST_VERSION:
- elf_strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
+ safe_strcpy(parms->guest_ver, str);
break;
case XEN_ELFNOTE_XEN_VERSION:
- elf_strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
+ safe_strcpy(parms->xen_ver, str);
break;
case XEN_ELFNOTE_PAE_MODE:
if (0 == strcmp(str, "yes"))
@@ -224,13 +224,13 @@ int elf_xen_parse_guest_info(struct elf_binary *elf,
/* strings */
if (0 == strcmp(name, "LOADER"))
- elf_strlcpy(parms->loader, value, sizeof(parms->loader));
+ safe_strcpy(parms->loader, value);
if (0 == strcmp(name, "GUEST_OS"))
- elf_strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
+ safe_strcpy(parms->guest_os, value);
if (0 == strcmp(name, "GUEST_VER"))
- elf_strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
+ safe_strcpy(parms->guest_ver, value);
if (0 == strcmp(name, "XEN_VER"))
- elf_strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
+ safe_strcpy(parms->xen_ver, value);
if (0 == strcmp(name, "PAE"))
{
if (0 == strcmp(value, "yes[extended-cr3]"))
diff --git a/xen/common/libelf/libelf-private.h b/xen/common/libelf/libelf-private.h
index 146251fe00..c404638f66 100644
--- a/xen/common/libelf/libelf-private.h
+++ b/xen/common/libelf/libelf-private.h
@@ -21,8 +21,6 @@
#define bswap_32(x) swab32(x)
#define bswap_64(x) swab64(x)
-#define elf_strlcpy(d,s,c) strlcpy(d,s,c)
-
#else /* !__XEN__ */
#include <stdio.h>
@@ -52,13 +50,10 @@
xc_set_error(XC_INVALID_KERNEL, fmt , ## args ); \
} while (0)
-/* SysV unices have no strlcpy/strlcat. */
-static inline size_t elf_strlcpy(char *dest, const char *src, size_t size)
-{
- strncpy(dest, src, size-1);
- dest[size-1] = '\0';
- return strlen(src);
-}
+#define safe_strcpy(d,s) \
+do { strncpy((d),(s),sizeof((d))-1); \
+ (d)[sizeof((d))-1] = '\0'; \
+} while (0)
#endif