Commit 04d4653e664 for php
commit 04d4653e6644054ba4507c18ac1e434aa315544d
Author: lazerg <lazerg2@gmail.com>
Date: Tue Dec 1 06:40:11 2026 +0500
standard: dns_get_record() reads A record bytes past a short RDATA
For an A record, php_parserr() only checked that 4 bytes were left in the
whole message, not in the record itself. With an RDLENGTH below 4, the missing
bytes came from the next record, so dns_get_record() returned a made-up
address like 9.192.12.0. A short A record is now treated as malformed, the
same way other bad RDATA already goes to fail.
CHECKCP(dlen) already runs before the switch, so dlen >= 4 also keeps the read
inside the message. I checked it with the reporter's fake DNS server: the bogus
record is gone and well-formed replies are unchanged. No .phpt, since the BIND
server used by the DNS tests won't serve an A record with short RDATA.
Fix GH-25968
Close GH-25984
diff --git a/NEWS b/NEWS
index 3ce05cf1546..5adcddfdca7 100644
--- a/NEWS
+++ b/NEWS
@@ -331,6 +331,8 @@ PHP NEWS
uninitialized memory). (Matyapiro31)
. Fixed bug GH-25693 (Use-after-free of the last response headers in a
stream wrapper closed at shutdown). (lazerg)
+ . Fixed bug GH-25968 (dns_get_record() reads A record bytes past a short
+ RDATA). (lazerg)
- Streams:
. Fixed bug GH-22063 (Stream filter chain UAF on self-removal during
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index c713d235b5b..96a20ef9c0c 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -500,7 +500,9 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
switch (type) {
case DNS_T_A:
- CHECKCP(4);
+ if (dlen < 4) {
+ goto fail;
+ }
add_assoc_string(subarray, "type", "A");
snprintf(name, sizeof(name), "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]);
add_assoc_string(subarray, "ip", name);