Skip to contentSkip to conversation

dnsproxy: Fix cached ttl update

PATCH Superseded Brian Fukano 2 participants 2 messages Apr 8, 2024 – Apr 17, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dnsproxy: Fix cached ttl update

This bug was exposed after fixing the signedness comparison warnings found in dnsproxy.c update_cached_ttl() consistently comes up two bytes short when processing the last record.

---
 src/dnsproxy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/dnsproxy.c +1 -2
index d4242560..506e1b9d 100644
@@ -508,8 +508,7 @@ static void send_cached_response(int sk, const unsigned char *ptr, size_t len,
 	if (answers == 0)
 		hdr->aa = 1;
 	else {
-		const int adj_len = len - 2;
-		update_cached_ttl((unsigned char *)hdr, adj_len, ttl);
+		update_cached_ttl((unsigned char *)hdr, len, ttl);
 	}
 
 	debug("sk %d id 0x%04x answers %d ptr %p length %zd dns %zd",
Signature · 1 line
2.34.1
#1 lore raw

Hi Brian,

Quoted 12 lines · Brian Fukano

This bug was exposed after fixing the signedness comparison warnings found in dnsproxy.c update_cached_ttl() consistently comes up two bytes short when processing the last record.

---
  src/dnsproxy.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
src/dnsproxy.c +0 -0
index d4242560..506e1b9d 100644

src/dnsproxy.c static void send_cached_response(int sk, const unsigned char *ptr, size_t len, · line 511

Quoted 6 lines
src/dnsproxy.c +1 -2
@@ -508,8 +508,7 @@ static void send_cached_response(int sk, const unsigned char *ptr, size_t len,
  	if (answers == 0)
  		hdr->aa = 1;
  	else {
-		const int adj_len = len - 2;
-		update_cached_ttl((unsigned char *)hdr, adj_len, ttl);
+		update_cached_ttl((unsigned char *)hdr, len, ttl);

Looks like this should be dns_len? Also, the { } around the else are no longer needed.

https://datatracker.ietf.org/doc/html/rfc1035#section-4.2.2

src/dnsproxy.c static void send_cached_response(int sk, const unsigned char *ptr, size_t len, · line 514

Quoted 3 lines
src/dnsproxy.c +0 -0
  	}
 
  	debug("sk %d id 0x%04x answers %d ptr %p length %zd dns %zd",

Regards,
-Denis