Fix crash when no upstream servers defined. v2.91 v2.91rc6
authorTijs Van Buggenhout <tijs.van.buggenhout@axsguard.com>
Fri, 14 Mar 2025 15:06:42 +0000 (15:06 +0000)
committerSimon Kelley <simon@thekelleys.org.uk>
Fri, 14 Mar 2025 15:09:35 +0000 (15:09 +0000)
This is a regession introduced in 3b6df06fb8cb3652d2e7afd085fae3f416408013.

When dnsmasq is started without upstreams (yet), but a
DNS query comes in that needs forwarding dnsmasq now potentially crashes as
the value for "first" variable is undetermined.

A segmentation violation occurs when the index
is out of bounds of  serverarray.

Credits go to pedro0311 <pedro@freshtomato.org>

src/forward.c

index 8207a7e..28b6ffd 100644 (file)
@@ -354,8 +354,6 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr,
          flags = 0;
        }
 
-      master = daemon->serverarray[first];
-
       /* don't forward A or AAAA queries for simple names, except the empty name */
       if (!flags &&
          option_bool(OPT_NODOTS_LOCAL) &&
@@ -367,7 +365,9 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr,
       /* Configured answer. */
       if (flags || ede == EDE_NOT_READY)
        goto reply;
-      
+
+      master = daemon->serverarray[first];
+
       if (!(forward = get_new_frec(now, master, 0)))
        goto reply;
       /* table full - flags == 0, return REFUSED */