From: Vincent Bernat Date: Sat, 7 Mar 2009 09:37:29 +0000 (+0100) Subject: Fix unaligned memory access in ctl.c using memcpy instead of pointer X-Git-Tag: 0.4.0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70d8fe9813a02dd9bda175b5a77be7aba83a0541;p=thirdparty%2Flldpd.git Fix unaligned memory access in ctl.c using memcpy instead of pointer magic. This needs to be done on encoding/decoding too. --- diff --git a/src/ctl.c b/src/ctl.c index f2b582fc..2268e0b8 100644 --- 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");