@@ -709,6 +709,24 @@ static uint8_t resp_truncated_response_ipv4_5[] = {
709
709
0x00 , 0x04 ,
710
710
};
711
711
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
+
712
730
static uint8_t resp_valid_response_ipv4_6 [] = {
713
731
/* DNS msg header (12 bytes) */
714
732
0xb0 , 0x41 , 0x81 , 0x80 , 0x00 , 0x01 , 0x00 , 0x01 ,
@@ -1093,8 +1111,13 @@ static void run_dns_malformed_response(const char *test_case,
1093
1111
1094
1112
dns_id = dns_unpack_header_id (dns_msg .msg );
1095
1113
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
+ }
1098
1121
1099
1122
ret = dns_validate_msg (& dns_ctx , & dns_msg , & dns_id , & query_idx ,
1100
1123
NULL , & query_hash );
@@ -1198,6 +1221,7 @@ static void test_dns_malformed_responses(void)
1198
1221
RUN_MALFORMED_TEST (resp_truncated_response_ipv4_3 );
1199
1222
RUN_MALFORMED_TEST (resp_truncated_response_ipv4_4 );
1200
1223
RUN_MALFORMED_TEST (resp_truncated_response_ipv4_5 );
1224
+ RUN_MALFORMED_TEST (resp_truncated_response_ipv4_6 );
1201
1225
}
1202
1226
1203
1227
ZTEST (dns_packet , test_dns_malformed_and_valid_responses )
0 commit comments