[Dnsmasq-discuss] Subject: [Bug] heap-buffer-overflow read in option parsing (server=/domain/ ...), dnsmasq 2.93

陈孟达 mengda2020 at iscas.ac.cn
Tue Nov 17 03:50:34 UTC 2026


Hello,


I found a heap-buffer-overflow (out-of-bounds read) in dnsmasq's configuration parser. A malformed server= line (also address= and local=) makes the daemon read past the 1024-byte line buffer while parsing the configuration at startup or during --test.


Version
-------
dnsmasq 2.93 (release tarball). The same code is present at commit cf08eeee12b0f76a1259736c7795bfae82e08d2c (2.93-dev).


Reproducer
----------
Minimal configuration file, 21 bytes, one line terminated by a newline:


    server=/a/ b/1.1.1.1


i.e. the bytes


    73 65 72 76 65 72 3d 2f 61 2f 20 62 2f 31 2e 31 2e 31 2e 31 0a


Command:


    ./dnsmasq --test --conf-file=min.conf


Result, gcc 12 plus ASan, aarch64 Linux:


    ==...==ERROR: AddressSanitizer: heap-buffer-overflow on address ...
    READ of size 1004 at ... thread T0
        #0 ... in __interceptor_strlen
        #1 ... in check_name src/util.c:139
        #2 ... in canonicalise src/util.c:251
        #3 ... in add_update_server src/domain-match.c:677
        #4 ... in one_opt src/option.c:3142
        #5 ... in read_file src/option.c:5599
        #6 ... in one_file src/option.c:5705
        #7 ... in read_opts src/option.c:6090
        #8 ... in main src/dnsmasq.c:115


The 1024-byte line buffer is allocated by get_line_alloc() (src/util.c:1054) via whine_realloc_real() (src/util.c:967); the over-read starts inside it and runs past the end of the allocation.


The original 71-byte test file from my fuzzing run also reproduces (READ of size 953), as do these variants:


    server=/a/ x/1.2.3.4
    server=/a/ b/1.2.3.4
    address=/a/ b/1.1.1.1
    local=/a/ b/
    server=/a/<TAB>b/1.1.1.1


server=/a/ /1.2.3.4 is rejected as a syntax error and server=/a  /1.2.3.4 (two spaces) parses fine. The trigger is an extra whitespace-separated token after the /domain/ group that is neither a server address nor a URL.


Root cause
----------
For server=, address= and local=, one_opt() (src/option.c, around lines 3030 to 3150) parses the optional domain list:


    domain = lastdomain = ++arg;
    while ((last = split_chr(arg, '/'))) {
        lastdomain = arg;
        arg = last;
    }


split_chr() (src/option.c:698) replaces the found '/' with a space and then NUL-terminates backwards over spaces, so each domain segment is delimited in place. When the rest of the line contains an extra token that is not a URL or server specification, the final lastdomain pointer does not point at a NUL-terminated domain; add_update_server() -> canonicalise() -> check_name() then calls strlen() on it (src/util.c:139) and walks past the end of the line buffer.


Suggested fix
-------------
Reject or ignore tokens after a /domain/ group that are neither a server address, an interface, a source address, nor a URL, instead of passing the leftover token to add_update_server().
Defensively bound the domain before canonicalise() and check_name(): the domain is already delimited by the '/' or whitespace in the line buffer, so terminate it explicitly rather than relying on the in-place NUL that split_chr() writes only for the segments it consumed.


Impact
------
Parsing a crafted configuration file causes an out-of-bounds heap read during startup or --test; the tested ASan build aborts, demonstrating a local denial-of-service condition. Configuration files may be generated by management planes or provisioning pipelines, so a malformed generated line can prevent the resolver from starting. The trigger demonstrated here is local configuration parsing, not a remote network attack, and no information disclosure was demonstrated.


I can provide my name and affiliation if the report is credited or a CVE is assigned.




Regards,

Mengda Chen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20261117/93d13c02/attachment-0001.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dnsmasq-asan.txt
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20261117/93d13c02/attachment-0001.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: min.conf
Type: application/octet-stream
Size: 21 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20261117/93d13c02/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poc.conf
Type: application/octet-stream
Size: 71 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20261117/93d13c02/attachment-0003.obj>


More information about the Dnsmasq-discuss mailing list