Skip to content

Commit 3d61897

Browse files
jukkarnashif
authored andcommitted
net: dns: Verify that DNS id and flags can be read
The DNS message must be long enough for id and flags fields. Signed-off-by: Jukka Rissanen <[email protected]> Signed-off-by: Flavio Ceolin <[email protected]>
1 parent f5b0c39 commit 3d61897

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

subsys/net/lib/dns/resolve.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ static int dns_read(struct dns_resolve_context *ctx,
353353
dns_msg.msg = dns_data->data;
354354
dns_msg.msg_size = data_len;
355355

356+
/* Make sure that we can read DNS id, flags and rcode */
357+
if (dns_msg.msg_size < (sizeof(*dns_id) + sizeof(uint16_t))) {
358+
ret = DNS_EAI_FAIL;
359+
goto quit;
360+
}
361+
356362
/* The dns_unpack_response_header() has design flaw as it expects
357363
* dns id to be given instead of returning the id to the caller.
358364
* In our case we would like to get it returned instead so that we

0 commit comments

Comments
 (0)