Skip to content

Commit

Permalink
net: dns: Validate source buffer length properly
Browse files Browse the repository at this point in the history
Make sure that when copying the qname, the source buffer is large
enough for the data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
  • Loading branch information
jukkar authored and TaiJuWu committed Dec 2, 2024
1 parent b799bdc commit eedd1bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/net/lib/dns/dns_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ int dns_copy_qname(uint8_t *buf, uint16_t *len, uint16_t size,
/* validate that the label (i.e. size + elements),
* fits the current msg buffer
*/
if (DNS_LABEL_LEN_SIZE + lb_size > size - *len) {
if (DNS_LABEL_LEN_SIZE + lb_size > MIN(size - *len, msg_size - pos)) {
rc = -ENOMEM;
break;
}
Expand Down

0 comments on commit eedd1bf

Please sign in to comment.