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