From 70d8fe9813a02dd9bda175b5a77be7aba83a0541 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 7 Mar 2009 10:37:29 +0100 Subject: [PATCH] Fix unaligned memory access in ctl.c using memcpy instead of pointer magic. This needs to be done on encoding/decoding too. --- src/ctl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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"); -- 2.39.5