Skip to content

Commit

Permalink
Fix #77369 - memcpy with negative length via crafted DNS response
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jan 6, 2019
1 parent 31f59e1 commit 8d3dfab
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
GETLONG(ttl, cp);
GETSHORT(dlen, cp);
CHECKCP(dlen);
if (dlen == 0) {
/* No data in the response - nothing to do */
return NULL;
}
if (type_to_fetch != T_ANY && type != type_to_fetch) {
cp += dlen;
return cp;
Expand Down Expand Up @@ -549,6 +553,9 @@ static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_t
CHECKCP(n);
add_assoc_stringl(subarray, "tag", (char*)cp, n);
cp += n;
if ( (size_t) dlen < ((size_t)n) + 2 ) {
return NULL;
}
n = dlen - n - 2;
CHECKCP(n);
add_assoc_stringl(subarray, "value", (char*)cp, n);
Expand Down

0 comments on commit 8d3dfab

Please sign in to comment.