Fix crash when no upstream servers defined.

This is a regession introduced in 3b6df06fb8.

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>
This commit is contained in:
Tijs Van Buggenhout
2025-03-14 15:06:42 +00:00
committed by Simon Kelley
parent 5897e79d05
commit 9af15871e6

View File

@@ -354,8 +354,6 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr,
flags = 0; flags = 0;
} }
master = daemon->serverarray[first];
/* don't forward A or AAAA queries for simple names, except the empty name */ /* don't forward A or AAAA queries for simple names, except the empty name */
if (!flags && if (!flags &&
option_bool(OPT_NODOTS_LOCAL) && option_bool(OPT_NODOTS_LOCAL) &&
@@ -368,6 +366,8 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr,
if (flags || ede == EDE_NOT_READY) if (flags || ede == EDE_NOT_READY)
goto reply; goto reply;
master = daemon->serverarray[first];
if (!(forward = get_new_frec(now, master, 0))) if (!(forward = get_new_frec(now, master, 0)))
goto reply; goto reply;
/* table full - flags == 0, return REFUSED */ /* table full - flags == 0, return REFUSED */