Skip to content

[Standard] Bound-check RR parsing in dns_get_mx() answer loop - #295

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/dns-getmx-checkcp-84
Open

[Standard] Bound-check RR parsing in dns_get_mx() answer loop#295
iliaal wants to merge 1 commit into
PHP-8.4from
fix/dns-getmx-checkcp-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

The dns_get_mx() answer loop parsed answer records with raw GETSHORT() reads after unvalidated dn_skipname() advances and no CHECKCP guards, so a crafted DNS reply whose last record name ends exactly at the end of the response buffer made the type/class/ttl/rdlength and weight reads run up to about 12 bytes past the end of the 64K querybuf stack union. This adds explicit bounds guards mirroring php_parserr()'s CHECKCP(10) and CHECKCP(2) checks before the fixed-size field reads; rdata skips stay bounded by the cp < end loop condition and dn_skipname()'s own eom check. Sibling audit found every other GETSHORT()/dn_expand() walk confined to php_parserr(), which is already guarded on all paths. No .phpt is shipped because a red test would need an LD_PRELOAD resolver mock serving a truncated hostile reply, which is not portable under run-tests.php; this is a code-inspection fix.

The dns_get_mx() answer loop parsed records with raw GETSHORT() after
unvalidated dn_skipname() advances, so a reply whose last record name ends
exactly at end of buffer made the type/class/ttl/rdlength and weight reads
run up to ~12 bytes past the 64K querybuf stack union. Guard the fixed-size
header fields the same way php_parserr() does with CHECKCP(10)/CHECKCP(2);
rdata skips remain bounded by the cp < end loop condition and dn_skipname()'s
own eom check. Sibling audit: every other GETSHORT()/dn_expand() walk lives
inside php_parserr(), which is already CHECKCP-guarded on all paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant