]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Fix unaligned memory access in ctl.c using memcpy instead of pointer
authorVincent Bernat <bernat@luffy.cx>
Sat, 7 Mar 2009 09:37:29 +0000 (10:37 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sat, 7 Mar 2009 09:37:29 +0000 (10:37 +0100)
magic. This needs to be done on encoding/decoding too.

src/ctl.c

index f2b582fc8c3720c7098e979bf59f415e285575f2..2268e0b888af647f5b21512dc79807c12bd0e6a0 100644 (file)
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -260,7 +260,8 @@ unpack_string(struct hmsg *h, void **p, void *s,
     const struct formatdef *ct, struct gc_l *pointers)
 {
        char *string;
-       int len = *(int*)*p;
+       int len;
+       memcpy(&len, *p, sizeof(int));
        *p += sizeof(int);
        if (len == -1) {
                string = NULL;
@@ -288,7 +289,7 @@ pack_chars(struct hmsg *h, void **p, void *s,
        int string_len;
        string = *(char **)s;
        s += sizeof(char *);
-       string_len = *(int *)s;
+       memcpy(&string_len, s, sizeof(int));
 
        if (h->hdr.len + string_len + sizeof(int) > MAX_HMSGSIZE -
            sizeof(struct hmsg_hdr)) {
@@ -312,7 +313,8 @@ unpack_chars(struct hmsg *h, void **p, void *s,
                char *string;
                int len;
        } reals __attribute__ ((__packed__));
-       int len = *(int*)*p;
+       int len;
+       memcpy(&len, *p, sizeof(int));
        *p += sizeof(int);
        if ((string = (char *)malloc(len)) == NULL) {
                LLOG_WARN("unable to allocate new string");