Skip to content

Commit 805169c

Browse files
committed
libs/netdb: Fix dns_recv_response() to dns_answer_s size
This commit avoid that dns_recv_response() accepts fewer tha 10 bytes that could end up with an OOB read. Signed-off-by: Alan C. Assis <acassis@gmail.com>
1 parent 96041a7 commit 805169c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

libs/libc/netdb/lib_dnsquery.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,19 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
694694
break;
695695
}
696696

697+
/* Verify that a complete answer header (10 bytes: type, class,
698+
* ttl[2], len) is available before casting to dns_answer_s.
699+
* Without this check, accessing ans->ttl and ans->type/class/len
700+
* would be an OOB read if fewer than 10 bytes remain.
701+
*/
702+
703+
if (nameptr + sizeof(struct dns_answer_s) > endofbuffer)
704+
{
705+
ret = -EILSEQ;
706+
nwarn("DNS answer header truncated\n");
707+
break;
708+
}
709+
697710
ans = (FAR struct dns_answer_s *)nameptr;
698711

699712
ninfo("Answer: type=%04x, class=%04x, ttl=%06x, length=%04x\n",

0 commit comments

Comments
 (0)