aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/services/dnsmasq/patches/0040-Fix-crash-when-negative-SRV-response-over-TCP-gets-s.patch
blob: 5b1d59566da80b443a743c8858a96324c8a0d1b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From e710c34469af4378c2db6fa0b0be88313adcb68f Mon Sep 17 00:00:00 2001
From: Alin Nastac <alin.nastac@gmail.com>
Date: Mon, 30 Sep 2019 15:30:26 +0100
Subject: [PATCH] Fix crash when negative SRV response over TCP gets stored in
 LRU cache entry.

Patch extended to receive side of pipe by SRK.
---
 src/cache.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/src/cache.c
+++ b/src/cache.c
@@ -665,7 +665,11 @@ void cache_end_insert(void)
 	      if (flags & (F_IPV4 | F_IPV6 | F_DNSKEY | F_DS | F_SRV))
 		read_write(daemon->pipe_to_parent, (unsigned char *)&new_chain->addr, sizeof(new_chain->addr), 0);
 	      if (flags & F_SRV)
-		 blockdata_write(new_chain->addr.srv.target, new_chain->addr.srv.targetlen, daemon->pipe_to_parent);
+		{
+		  /* A negative SRV entry is possible and has no data, obviously. */
+		  if (!(flags & F_NEG))
+		    blockdata_write(new_chain->addr.srv.target, new_chain->addr.srv.targetlen, daemon->pipe_to_parent);
+		}
 #ifdef HAVE_DNSSEC
 	      if (flags & F_DNSKEY)
 		{
@@ -737,7 +741,7 @@ int cache_recv_insert(time_t now, int fd
 	  if (!read_write(fd, (unsigned char *)&addr, sizeof(addr), 1))
 	    return 0;
 
-	  if (flags & F_SRV && !(addr.srv.target = blockdata_read(fd, addr.srv.targetlen)))
+	  if ((flags & F_SRV) && !(flags & F_NEG) && !(addr.srv.target = blockdata_read(fd, addr.srv.targetlen)))
 	    return 0;
 	
 #ifdef HAVE_DNSSEC