Skip to content

Commit 9e7e0e4

Browse files
committed
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]>
1 parent 5653e9e commit 9e7e0e4

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
@@ -380,7 +380,7 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
380380
lb_size = msg[pos];
381381

382382
/* pointer */
383-
if (lb_size > DNS_LABEL_MAX_SIZE) {
383+
if ((lb_size & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
384384
uint8_t mask = DNS_LABEL_MAX_SIZE;
385385

386386
if (pos + 1 >= msg_size) {
@@ -403,6 +403,9 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
403403
}
404404

405405
continue;
406+
} else if (lb_size & NS_CMPRSFLGS) {
407+
rc = -EINVAL;
408+
break;
406409
}
407410

408411
/* validate that the label (i.e. size + elements),
@@ -491,7 +494,7 @@ static int dns_unpack_name(const uint8_t *msg, int maxlen, const uint8_t *src,
491494
}
492495

493496
while ((val = *curr_src++)) {
494-
if (val & NS_CMPRSFLGS) {
497+
if ((val & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
495498
/* Follow pointer */
496499
int pos;
497500

0 commit comments

Comments
 (0)