@@ -709,6 +709,24 @@ static uint8_t resp_truncated_response_ipv4_5[] = {
709709 0x00 , 0x04 ,
710710};
711711
712+ static uint8_t resp_truncated_response_ipv4_6 [] = {
713+ /* DNS msg header (12 bytes) */
714+ /* Id (0) */
715+ 0x00 , 0x00 ,
716+ /* Flags (response, rcode = 1) */
717+ 0x80 , 0x01 ,
718+ /* Number of questions */
719+ 0x00 , 0x01 ,
720+ /* Number of answers */
721+ 0x00 , 0x00 ,
722+ /* Number of authority RRs */
723+ 0x00 , 0x00 ,
724+ /* Number of additional RRs */
725+ 0x00 , 0x00 ,
726+
727+ /* Rest of the data is missing */
728+ };
729+
712730static uint8_t resp_valid_response_ipv4_6 [] = {
713731 /* DNS msg header (12 bytes) */
714732 0xb0 , 0x41 , 0x81 , 0x80 , 0x00 , 0x01 , 0x00 , 0x01 ,
@@ -1093,8 +1111,13 @@ static void run_dns_malformed_response(const char *test_case,
10931111
10941112 dns_id = dns_unpack_header_id (dns_msg .msg );
10951113
1096- setup_dns_context (& dns_ctx , 0 , dns_id , query , sizeof (query ),
1097- DNS_QUERY_TYPE_A );
1114+ /* If the message is longer than 12 bytes, it could be a valid DNS message
1115+ * in which case setup the context for the reply.
1116+ */
1117+ if (len > 12 ) {
1118+ setup_dns_context (& dns_ctx , 0 , dns_id , query , sizeof (query ),
1119+ DNS_QUERY_TYPE_A );
1120+ }
10981121
10991122 ret = dns_validate_msg (& dns_ctx , & dns_msg , & dns_id , & query_idx ,
11001123 NULL , & query_hash );
@@ -1198,6 +1221,7 @@ static void test_dns_malformed_responses(void)
11981221 RUN_MALFORMED_TEST (resp_truncated_response_ipv4_3 );
11991222 RUN_MALFORMED_TEST (resp_truncated_response_ipv4_4 );
12001223 RUN_MALFORMED_TEST (resp_truncated_response_ipv4_5 );
1224+ RUN_MALFORMED_TEST (resp_truncated_response_ipv4_6 );
12011225}
12021226
12031227ZTEST (dns_packet , test_dns_malformed_and_valid_responses )
0 commit comments