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

Simon Kelley simon at thekelleys.org.uk
Wed Oct 21 21:15:46 UTC 2026


Patch applied, thanks.


Simon.


On 21/10/2026 19:12, Dominik Derigs wrote:
> 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;




More information about the Dnsmasq-discuss mailing list