Skip to content

Commit 8d3dfab

Browse files
committed
Fix #77369 - memcpy with negative length via crafted DNS response
1 parent 31f59e1 commit 8d3dfab

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ext/standard/dns.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
459459
GETLONG(ttl, cp);
460460
GETSHORT(dlen, cp);
461461
CHECKCP(dlen);
462+
if (dlen == 0) {
463+
/* No data in the response - nothing to do */
464+
return NULL;
465+
}
462466
if (type_to_fetch != T_ANY && type != type_to_fetch) {
463467
cp += dlen;
464468
return cp;
@@ -549,6 +553,9 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
549553
CHECKCP(n);
550554
add_assoc_stringl(subarray, "tag", (char*)cp, n);
551555
cp += n;
556+
if ( (size_t) dlen < ((size_t)n) + 2 ) {
557+
return NULL;
558+
}
552559
n = dlen - n - 2;
553560
CHECKCP(n);
554561
add_assoc_stringl(subarray, "value", (char*)cp, n);

0 commit comments

Comments
 (0)