Skip to content

Commit 54ac4ee

Browse files
jukkarkartben
authored andcommitted
net: dns: Check compression flag properly
Allow only 0xc (0b11) as two highest bit to mark the compression when parsing the CNAME response. See RFC 9267 ch. 2 for details. Signed-off-by: Jukka Rissanen <[email protected]> (cherry picked from commit 137eba4)
1 parent f24adc8 commit 54ac4ee

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

subsys/net/lib/dns/dns_pack.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
386386
lb_size = msg[pos];
387387

388388
/* pointer */
389-
if (lb_size > DNS_LABEL_MAX_SIZE) {
389+
if ((lb_size & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
390390
uint8_t mask = DNS_LABEL_MAX_SIZE;
391391

392392
if (pos + 1 >= msg_size) {
@@ -409,6 +409,9 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
409409
}
410410

411411
continue;
412+
} else if (lb_size & NS_CMPRSFLGS) {
413+
rc = -EINVAL;
414+
break;
412415
}
413416

414417
/* validate that the label (i.e. size + elements),
@@ -498,7 +501,7 @@ static int dns_unpack_name(const uint8_t *msg, int maxlen, const uint8_t *src,
498501
}
499502

500503
while ((val = *curr_src++)) {
501-
if (val & NS_CMPRSFLGS) {
504+
if ((val & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
502505
/* Follow pointer */
503506
int pos;
504507

0 commit comments

Comments
 (0)