This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 317bd40 net/dns:fix unaligned access in dns query
317bd40 is described below
commit 317bd40fecb88c28b2ea532c8c7108b7947e8179
Author: Virus.V <[email protected]>
AuthorDate: Thu Jun 10 10:02:03 2021 +0800
net/dns:fix unaligned access in dns query
---
libs/libc/netdb/lib_dnsquery.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c
index b24d4a1..97d9b3f 100644
--- a/libs/libc/netdb/lib_dnsquery.c
+++ b/libs/libc/netdb/lib_dnsquery.c
@@ -336,6 +336,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u
*addr, int naddr,
FAR struct dns_question_s *que;
uint16_t nquestions;
uint16_t nanswers;
+ uint16_t temp;
int naddr_read;
int ret;
@@ -436,11 +437,12 @@ static int dns_recv_response(int sd, FAR union dns_addr_u
*addr, int naddr,
/* Validate query type and class */
que = (FAR struct dns_question_s *)nameptr;
- ninfo("Question: type=%04x, class=%04x\n",
- ntohs(que->type), ntohs(que->class));
- if (que->type != qinfo->rectype ||
- que->class != HTONS(DNS_CLASS_IN))
+ /* N.B. Unaligned access may occur here */
+
+ temp = HTONS(DNS_CLASS_IN);
+ if (memcmp(&que->type, &qinfo->rectype, sizeof(uint16_t)) != 0 ||
+ memcmp(&que->class, &temp, sizeof(uint16_t)) != 0)
{
nerr("ERROR: DNS response with wrong question\n");
return -EBADMSG;