Dear Simon,

server=//1.2.3.4 can be used to specify a server to be used for
unqualified names. However, if we want to combine this feature with
other domains, the server config option is parsed incorrectly.

A fix is attached.

---

Example 1:
> server=//192.168.2.1
> server=/fritz.box/192.168.2.1

Log:
> Aug 20 13:00:34 dnsmasq[1151247]: using nameserver 192.168.2.1#53 for
> unqualified names (no DNSSEC)
> Aug 20 13:00:34 dnsmasq[1151247]: using nameserver 192.168.2.1#53 for
> domain fritz.box (no DNSSEC)

CORRECT

Example 2:
> server=//fritz.box/192.168.2.1

Log:

> Aug 20 12:33:41 dnsmasq[1147692]: using nameserver 192.168.2.1#53 for
> unqualified names (no DNSSEC)
> Aug 20 12:33:41 dnsmasq[1147692]: using nameserver 192.168.2.1#53 for
> unqualified names (no DNSSEC)

WRONG (not using the server for fritz.box)

Example 3:
> server=/fritz.box//192.168.2.1

Log:
> Aug 20 12:30:27 dnsmasq[1147304]: using nameserver 192.168.2.1#53 for
> domain fritz.box (no DNSSEC)
> Aug 20 12:30:27 dnsmasq[1147304]: using nameserver 192.168.2.1#53

WRONG (uses server for all domains instead of only unqualified)

----

The bug has been introduced about two months ago in
12a9aa7c628e2d7dcd34949603848a3fb53fce9c

The issue is now caused by interpreting the server flags only once. If
// is the first domain, SERV_FOR_NODOTS is set to all domains extracted
from a server config line. If // appears later on, SERV_FOR_NODOTS is
never set, leading to the misinterpretation that server=//192.168.2.1
is the same as server=192.168.2.1.

The attached patch fixes this by adding SERV_FOR_NODOTS *selectively*
for empty domains. It does this only when // is detected.

All three examples work as expected now.

Best,
Dominik
From 1b7420af92f474f18ebb74b960a8cefb7fde70cd Mon Sep 17 00:00:00 2001
From: Dominik DL6ER <dl...@dl6er.de>
Date: Fri, 20 Aug 2021 13:05:35 +0200
Subject: [PATCH] Fix empty domain in server option parsing when more than one
 domain is given

Signed-off-by: DL6ER <dl...@dl6er.de>
---
 src/option.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/option.c b/src/option.c
index 3a87097..ffce9fc 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2700,11 +2700,6 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
 	  {
 	    if ((err = parse_server(arg, &serv_addr, &source_addr, interface, &flags)))
 	      ret_err(err);
-
-	    /* server=//1.2.3.4 is special. */
-	    if (strlen(domain) == 0 && lastdomain)
-	      flags |= SERV_FOR_NODOTS;
-
 	  }
 
 	if (servers_only && option == 'S')
@@ -2712,6 +2707,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
 	
 	while (1)
 	  {
+	    /* server=//1.2.3.4 is special. */
+	    if (strlen(domain) == 0 && lastdomain)
+	      flags |= SERV_FOR_NODOTS;
+	    else
+	      flags &= ~SERV_FOR_NODOTS;
+
 	    if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, &addr))
 	      ret_err(gen_err);
 	    
-- 
2.25.1

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to