Skip to content

Commit 984e87d

Browse files
committed
NSAPI - Don't send trailing garbage in DNS queries
Observed during investigation of #4246 - DNS queries sent the entire buffer, not just the bit filled in. Inefficient, especially for 6LoWPAN, and a security hole - the trailing data could be previously-used heap.
1 parent 8543279 commit 984e87d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

features/netsocket/nsapi_dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const
227227
uint8_t *question = packet;
228228
dns_append_question(&question, host, version);
229229

230-
err = socket.sendto(SocketAddress(dns_servers[i], 53), packet, DNS_BUFFER_SIZE);
230+
err = socket.sendto(SocketAddress(dns_servers[i], 53), packet, question - packet);
231231
// send may fail for various reasons, including wrong address type - move on
232232
if (err < 0) {
233233
continue;

0 commit comments

Comments
 (0)