[Dnsmasq-discuss] [PATCH] Don't add an empty CNAME alias for a space before a comma.

Dominik Derigs git at dl6er.de
Wed Oct 21 18:12:37 UTC 2026


From: DL6ER <dl6er at dl6er.de>

split() replaces the comma with a space and then writes a NUL over
every space before it, so "a.example ,target.example" becomes
"a.example\0\0target.example". The --cname loop steps over one NUL
and the following spaces only, stops on the second NUL and adds an
empty alias, i.e., a CNAME for the root name. A second such entry is
then rejected as "duplicate CNAME".

Step over the NULs, too.

Signed-off-by: DL6ER <dl6er at dl6er.de>
---

Hi Simon,

a space before a comma in --cname adds an empty alias, i.e., a CNAME for the root name. split() leaves a NUL for each space before the comma, and the loop at the end of the LOPT_CNAME case steps over only one of them.

Reproducer:

    dnsmasq -d -p 5353 --no-resolv --cname='a.example ,target.example' --host-record=target.example,192.0.2.1
    dig @127.0.0.1 -p 5353 . A

This answers ". CNAME target.example" on current master, and two such --cname options fail with "duplicate CNAME". With the patch, "." gets no answer and the forms "a,b", "a, b", "a ,b", "a  ,  b ,c , 300" all give the expected aliases and TTL.

Best regards,
Dominik

 src/option.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/option.c b/src/option.c
index 44bd522..012b14a 100644
--- a/src/option.c
+++ b/src/option.c
@@ -5046,7 +5046,7 @@ err:
 	    new->target = target;
 	    new->ttl = ttl;
 
-	    for (arg += arglen+1; *arg && isspace((unsigned char)*arg); arg++);
+	    for (arg += arglen+1; arg != last && (!*arg || isspace((unsigned char)*arg)); arg++);
 	  }
       
 	break;
-- 
2.53.0




More information about the Dnsmasq-discuss mailing list