7d83209
From 2d5ed6400ba430f412ebc9748eb847771907776d Mon Sep 17 00:00:00 2001
7d83209
From: Daniel Stenberg <daniel@haxx.se>
7d83209
Date: Sat, 18 Dec 2010 22:20:16 +0100
7d83209
Subject: [PATCH] cleanup: avoid unsafe typecasts
7d83209
7d83209
Avoid the risk of reading 16bit data from an unaligned address by using
7d83209
a macro that is adapted for this.
7d83209
---
7d83209
 ares_parse_mx_reply.c  |    4 ++--
7d83209
 ares_parse_srv_reply.c |    6 +++---
7d83209
 2 files changed, 5 insertions(+), 5 deletions(-)
7d83209
7d83209
diff --git a/ares_parse_mx_reply.c b/ares_parse_mx_reply.c
7d83209
index 186ddd3..2180054 100644
7d83209
--- a/ares_parse_mx_reply.c
7d83209
+++ b/ares_parse_mx_reply.c
7d83209
@@ -47,7 +47,7 @@
7d83209
 
7d83209
 int
7d83209
 ares_parse_mx_reply (const unsigned char *abuf, int alen,
7d83209
-                      struct ares_mx_reply **mx_out)
7d83209
+                     struct ares_mx_reply **mx_out)
7d83209
 {
7d83209
   unsigned int qdcount, ancount, i;
7d83209
   const unsigned char *aptr, *vptr;
7d83209
@@ -134,7 +134,7 @@ ares_parse_mx_reply (const unsigned char *abuf, int alen,
7d83209
           mx_last = mx_curr;
7d83209
 
7d83209
           vptr = aptr;
7d83209
-          mx_curr->priority = ntohs (*((unsigned short *)vptr));
7d83209
+          mx_curr->priority = DNS__16BIT(vptr);
7d83209
           vptr += sizeof(unsigned short);
7d83209
 
7d83209
           status = ares_expand_name (vptr, abuf, alen, &mx_curr->host, &len;;
7d83209
diff --git a/ares_parse_srv_reply.c b/ares_parse_srv_reply.c
7d83209
index 7d443b3..9c7eb6e 100644
7d83209
--- a/ares_parse_srv_reply.c
7d83209
+++ b/ares_parse_srv_reply.c
7d83209
@@ -139,11 +139,11 @@ ares_parse_srv_reply (const unsigned char *abuf, int alen,
7d83209
           srv_last = srv_curr;
7d83209
 
7d83209
           vptr = aptr;
7d83209
-          srv_curr->priority = ntohs (*((unsigned short *)vptr));
7d83209
+          srv_curr->priority = DNS__16BIT(vptr);
7d83209
           vptr += sizeof(unsigned short);
7d83209
-          srv_curr->weight = ntohs (*((unsigned short *)vptr));
7d83209
+          srv_curr->weight = DNS__16BIT(vptr);
7d83209
           vptr += sizeof(unsigned short);
7d83209
-          srv_curr->port = ntohs (*((unsigned short *)vptr));
7d83209
+          srv_curr->port = DNS__16BIT(vptr);
7d83209
           vptr += sizeof(unsigned short);
7d83209
 
7d83209
           status = ares_expand_name (vptr, abuf, alen, &srv_curr->host, &len;;
7d83209
-- 
7d83209
1.7.4.2
7d83209