~samiam/MaraDNS

ref: 3.5.0021 MaraDNS/deadwood-github/update/3.2.06/deadwood-3.2.05-ID-mismatch.patch -rw-r--r-- 1.2 KiB
ca00f282 — Sam Trenholme MaraDNS release 3.5.0021 9 months ago
                                                                                
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
36
37
The issue was this: Deadwood copies the packet, changes its ID and RD bits,
then sends it upstream. When sending a SERVER FAIL to the client, it
gives them the packet with the changed ID and changed RD bit.

This patch preserves the original ID and RD bit.

diff --git a/deadwood-github/src/DwUdpSocket.c b/deadwood-github/src/DwUdpSocket.c
index 0845d5b..16f3242 100644
--- a/deadwood-github/src/DwUdpSocket.c
+++ b/deadwood-github/src/DwUdpSocket.c
@@ -613,6 +613,15 @@ void try_forward_local_udp_packet(SOCKET sock, int32_t local_id,
      int len, sockaddr_all_T *client,dw_str *query, int tcp_num,
      dw_str *orig_query) {
 
+	unsigned char p0 = 0, p1 = 0, p2 = 0;
+
+	if(packet == 0 || len < 12) { /* Sanity check */
+		return;
+	}
+	p0 = packet[0];
+	p1 = packet[1];
+	p2 = packet[2];
+
         /* If not cached, get a reply that we will cache and send back to
          * the client */
         if(forward_local_udp_packet(sock,local_id,from_ip,from_port,
@@ -630,6 +639,9 @@ void try_forward_local_udp_packet(SOCKET sock, int32_t local_id,
         }
 
         if(handle_overload == 1) {
+		packet[0] = p0;
+		packet[1] = p1;
+		packet[2] = p2;
                 send_server_fail(client,packet,len,sock,tcp_num);
         }
 }