Skip to content

Commit 16669ec

Browse files
jukkarkartben
authored andcommitted
tests: net: dns: Add test for invalid DNS answer parsing
Make sure we catch invalid answer during parsing. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 6e7fcff commit 16669ec

File tree

1 file changed

+21
-0
lines changed
  • tests/net/lib/dns_packet/src

1 file changed

+21
-0
lines changed

tests/net/lib/dns_packet/src/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,27 @@ ZTEST(dns_packet, test_dns_flags_len)
12661266
"DNS message length check failed (%d)", ret);
12671267
}
12681268

1269+
static uint8_t invalid_answer_resp_ipv4[18] = {
1270+
/* DNS msg header (12 bytes) */
1271+
0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
1272+
0x00, 0x00, 0x01, 0x00, 0x01,
1273+
};
1274+
1275+
ZTEST(dns_packet, test_dns_invalid_answer)
1276+
{
1277+
struct dns_msg_t dns_msg = { 0 };
1278+
enum dns_rr_type type;
1279+
uint32_t ttl;
1280+
int ret;
1281+
1282+
dns_msg.msg = invalid_answer_resp_ipv4;
1283+
dns_msg.msg_size = sizeof(invalid_answer_resp_ipv4);
1284+
dns_msg.answer_offset = 12;
1285+
1286+
ret = dns_unpack_answer(&dns_msg, 0, &ttl, &type);
1287+
zassert_equal(ret, -EINVAL, "DNS message answer check succeed (%d)", ret);
1288+
}
1289+
12691290
ZTEST_SUITE(dns_packet, NULL, NULL, NULL, NULL, NULL);
12701291
/* TODO:
12711292
* 1) add malformed DNS data (mostly done)

0 commit comments

Comments
 (0)