From 9af15871e6ef0ac845412e9a6c3ecfb0849374c8 Mon Sep 17 00:00:00 2001 From: Tijs Van Buggenhout Date: Fri, 14 Mar 2025 15:06:42 +0000 Subject: [PATCH] Fix crash when no upstream servers defined. 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 --- src/forward.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/forward.c b/src/forward.c index 8207a7e..28b6ffd 100644 --- a/src/forward.c +++ b/src/forward.c @@ -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 */