]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Fix] rdns: reject DNS labels that overrun the packet
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 20 May 2026 11:05:08 +0000 (12:05 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 20 May 2026 11:05:08 +0000 (12:05 +0100)
commitc2fd2e002fce1fa846bc9278da1616459b9a5092
treea2c732941209426eaf8315095f0d5abd406e5d1c
parent04fc040b5ce534c796878f802d531049e044dfc5
[Fix] rdns: reject DNS labels that overrun the packet

rdns_parse_labels computes the name length in a first pass that only
reads label length bytes, then a second pass copies the label data.
The first pass never checked that a label's data actually fits within
the packet, so a reply whose final label declared more bytes than
remained made the second-pass memcpy read past the end of the reply
buffer. On the DNS-over-TCP path that buffer is malloc'd to exactly
the advertised message size, so the over-read ran past the allocation.

Validate in the first pass that both plain and compressed label data
stay within the packet, and reject the name otherwise. Also fix an
off-by-one in rdns_decompress_label where an offset equal to the
packet length was accepted and read one byte past the end.
contrib/librdns/parse.c