4-byte memory access works only when pointer is 4-byte aligned. Use memcpy function, since 4-byte pointer alignment is not guaranteed. The same applies to 2-byte memory access.
Signed-off-by: Mario Schuknecht <[email protected]> --- src/dnsproxy.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dnsproxy.c b/src/dnsproxy.c index 3e32b5a..57f28fa 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -356,8 +356,8 @@ static int dns_name_length(unsigned char *buf) static void update_cached_ttl(unsigned char *buf, int len, int new_ttl) { unsigned char *c; - uint32_t *i; - uint16_t *w; + uint32_t i; + uint16_t w; int l; /* skip the header */ @@ -387,17 +387,17 @@ static void update_cached_ttl(unsigned char *buf, int len, int new_ttl) break; /* now the 4 byte TTL field */ - i = (uint32_t *)c; - *i = htonl(new_ttl); + i = htonl(new_ttl); + memcpy(c, &i, 4); c += 4; len -= 4; if (len < 0) break; /* now the 2 byte rdlen field */ - w = (uint16_t *)c; - c += ntohs(*w) + 2; - len -= ntohs(*w) + 2; + memcpy(&w, c, 2); + c += ntohs(w) + 2; + len -= ntohs(w) + 2; } } @@ -1344,7 +1344,7 @@ static void cache_refresh(void) static int reply_query_type(unsigned char *msg, int len) { unsigned char *c; - uint16_t *w; + uint16_t w; int l; int type; @@ -1358,8 +1358,8 @@ static int reply_query_type(unsigned char *msg, int len) /* now the query, which is a name and 2 16 bit words */ l = dns_name_length(c) + 1; c += l; - w = (uint16_t *) c; - type = ntohs(*w); + memcpy(&w, c, 2); + type = ntohs(w); return type; } -- 1.8.4.5 _______________________________________________ connman mailing list [email protected] https://lists.connman.net/mailman/listinfo/connman
