Skip to content

Commit 0ae7812

Browse files
rlubosnashif
authored andcommitted
net: dns_sd: Prevent dead code in query parsing
The number of buffer provided was verified in the final else block of a long validation sequence. It would never be executed though, as one of the conditions before would always evaluate to true. As the number of buffers provided verification appears to be significant in this case, as the buffers are referenced during other validations, move this check at the beginning of the sequence instead. This also eliminates the dead-code problem. Signed-off-by: Robert Lubos <[email protected]>
1 parent 40312a8 commit 0ae7812

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

subsys/net/lib/dns/dns_sd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,12 @@ int dns_sd_query_extract(const uint8_t *query, size_t query_size, struct dns_sd_
10641064
size[i] = 0;
10651065
}
10661066

1067+
if (qlabels > N) {
1068+
NET_DBG("too few buffers to extract query: qlabels: %zu, N: %zu",
1069+
qlabels, N);
1070+
return -ENOBUFS;
1071+
}
1072+
10671073
if (qlabels < DNS_SD_MIN_LABELS) {
10681074
NET_DBG("too few labels in query %zu, DNS_SD_MIN_LABELS: %d", qlabels,
10691075
DNS_SD_MIN_LABELS);
@@ -1120,10 +1126,6 @@ int dns_sd_query_extract(const uint8_t *query, size_t query_size, struct dns_sd_
11201126
NET_DBG("domain '%s' is invalid", record->domain);
11211127
return -EINVAL;
11221128
}
1123-
} else if (qlabels > N) {
1124-
NET_DBG("too few buffers to extract query: qlabels: %zu, N: %zu",
1125-
qlabels, N);
1126-
return -ENOBUFS;
11271129
}
11281130

11291131
return offset;

0 commit comments

Comments
 (0)