[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libelf cannot rely on the strlcpy() BSD-ism.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1170071220 0
# Node ID 1b32e279ddef03cfbfcbdbd368a990f97fd84e19
# Parent  5d9b72e640e050cbe5a1e3677c4ca7cb2cd868c1
libelf cannot rely on the strlcpy() BSD-ism.
Make a private definition based on strncpy and strlen.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 xen/common/libelf/libelf-dominfo.c |   16 ++++++++--------
 xen/common/libelf/libelf-private.h |   10 ++++++++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff -r 5d9b72e640e0 -r 1b32e279ddef xen/common/libelf/libelf-dominfo.c
--- a/xen/common/libelf/libelf-dominfo.c        Mon Jan 29 10:55:20 2007 +0000
+++ b/xen/common/libelf/libelf-dominfo.c        Mon Jan 29 11:47:00 2007 +0000
@@ -128,16 +128,16 @@ int elf_xen_parse_note(struct elf_binary
     switch (type)
     {
     case XEN_ELFNOTE_LOADER:
-       strlcpy(parms->loader, str, sizeof(parms->loader));
+       elf_strlcpy(parms->loader, str, sizeof(parms->loader));
        break;
     case XEN_ELFNOTE_GUEST_OS:
-       strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
+       elf_strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
        break;
     case XEN_ELFNOTE_GUEST_VERSION:
-       strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
+       elf_strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
        break;
     case XEN_ELFNOTE_XEN_VERSION:
-       strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
+       elf_strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
        break;
     case XEN_ELFNOTE_PAE_MODE:
        if (0 == strcmp(str, "yes"))
@@ -224,13 +224,13 @@ int elf_xen_parse_guest_info(struct elf_
 
        /* strings */
        if (0 == strcmp(name, "LOADER"))
-           strlcpy(parms->loader, value, sizeof(parms->loader));
+           elf_strlcpy(parms->loader, value, sizeof(parms->loader));
        if (0 == strcmp(name, "GUEST_OS"))
-           strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
+           elf_strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
        if (0 == strcmp(name, "GUEST_VER"))
-           strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
+           elf_strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
        if (0 == strcmp(name, "XEN_VER"))
-           strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
+           elf_strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
        if (0 == strcmp(name, "PAE"))
        {
            if (0 == strcmp(value, "yes[extended-cr3]"))
diff -r 5d9b72e640e0 -r 1b32e279ddef xen/common/libelf/libelf-private.h
--- a/xen/common/libelf/libelf-private.h        Mon Jan 29 10:55:20 2007 +0000
+++ b/xen/common/libelf/libelf-private.h        Mon Jan 29 11:47:00 2007 +0000
@@ -20,6 +20,8 @@
 #define bswap_16(x) swab16(x)
 #define bswap_32(x) swab32(x)
 #define bswap_64(x) swab64(x)
+
+#define elf_strlcpy(d,s,c) strlcpy(d,s,c)
 
 #else /* !__XEN__ */
 
@@ -50,6 +52,14 @@
         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);
+}
+
 #endif
 
 #endif /* __LIBELF_PRIVATE_H_ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.