Commit 1500de81 authored by Jukka Rissanen's avatar Jukka Rissanen Committed by Anas Nashif
Browse files

net: dns: Check recursive pointers for CNAME handling

Make sure that the CNAME handling checks recursive name pointers
and fails the response if recursion is detected.
See RFC 9267 ch. 2 for details.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@nordicsemi.no>
parent 9adcb8db
Loading
Loading
Loading
Loading
+15 −1
Changes for subsys/net/lib/dns/dns_pack.c: 15 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@

#include <string.h>
#include <zephyr/net/buf.h>
#include <zephyr/sys/bitarray.h>
#include <zephyr/net/dns_resolve.h>

#include "dns_pack.h"

@@ -361,10 +363,11 @@ int dns_unpack_response_query(struct dns_msg_t *dns_msg)
int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
		   struct dns_msg_t *dns_msg, uint16_t pos)
{
	SYS_BITARRAY_DEFINE(visited, DNS_RESOLVER_MAX_BUF_SIZE);
	uint16_t msg_size = dns_msg->msg_size;
	uint8_t *msg = dns_msg->msg;
	uint16_t lb_size;
	int rc = -EINVAL;
	int rc = -EINVAL, ret, prev;

	*len = 0U;

@@ -388,6 +391,17 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
			/* See: RFC 1035, 4.1.4. Message compression */
			pos = ((msg[pos] & mask) << 8) + msg[pos + 1];

			ret = sys_bitarray_test_and_set_bit(&visited, pos, &prev);
			if (ret < 0) {
				rc = -EINVAL;
				break;
			}

			if (prev) {
				rc = -ELOOP;
				break;
			}

			continue;
		}