b6cbd1
From 4f73394fdd95d3165b4391e1b0dedd57fced8c3b Mon Sep 17 00:00:00 2001
b6cbd1
From: Sara Golemon <pollita@php.net>
b6cbd1
Date: Tue, 10 Jun 2014 11:18:02 -0700
b6cbd1
Subject: [PATCH] Fix potential segfault in dns_get_record()
b6cbd1
b6cbd1
If the remote sends us a packet with a malformed TXT record,
b6cbd1
we could end up trying to over-consume the packet and wander
b6cbd1
off into overruns.
b6cbd1
---
b6cbd1
 ext/standard/dns.c | 4 ++++
b6cbd1
 1 file changed, 4 insertions(+)
b6cbd1
b6cbd1
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
b6cbd1
index 6a89446..214a7dc 100644
b6cbd1
--- a/ext/standard/dns.c
b6cbd1
+++ b/ext/standard/dns.c
b6cbd1
@@ -517,6 +517,10 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int
b6cbd1
 				
b6cbd1
 				while (ll < dlen) {
b6cbd1
 					n = cp[ll];
b6cbd1
+					if ((ll + n) >= dlen) {
b6cbd1
+						// Invalid chunk length, truncate
b6cbd1
+						n = dlen - (ll + 1);
b6cbd1
+					}
b6cbd1
 					memcpy(tp + ll , cp + ll + 1, n);
b6cbd1
 					add_next_index_stringl(entries, cp + ll + 1, n, 1);
b6cbd1
 					ll = ll + n + 1;
b6cbd1
-- 
b6cbd1
1.9.3
b6cbd1