Skip to content

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

Closed
iliaal wants to merge 9 commits into
PHP-8.4from
fix/dns-getmx-checkcp-84
Closed

iliaal wants to merge 9 commits into
PHP-8.4from
fix/dns-getmx-checkcp-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

dns_get_mx()'s answer loop read type/class/ttl/rdlength and weight via raw GETSHORT() after unvalidated dn_skipname() advances, so a reply whose last record name ends at the buffer end overran the 64K querybuf stack union by up to about 12 bytes. Checks mirroring php_parserr()'s CHECKCP(10)/CHECKCP(2) now guard those reads; rdata skips stay bounded by cp < end and dn_skipname()'s eom check. A sibling audit found every remaining GETSHORT()/dn_expand() walk inside guarded php_parserr(). No phpt ships since a red test would need an LD_PRELOAD resolver mock serving a truncated hostile reply.

devnexen and others added 9 commits September 18, 2026 21:01
…ansformation.

Fix php#23730

Importing a stylesheet from a php:function callback freed the stylesheet
libxslt was still applying, and the transformation methods kept using the
stale pointer to save the result. The transformation depth is now tracked
on the object and importStylesheet() throws while it is non-zero.

Close phpGH-23737
… callback.

Fix php#23747

ZipArchive::close() called from a progress or cancel callback ran a
nested zip_close() that failed, then zip_discard() freed the archive
while the outer zip_close() from close() or open() was still using it.
Track the close in progress and throw an Error from close() and open()
meanwhile.

Close phpGH-23749
…luation

Reconstructing the object from a php:function callback freed the context
libxml2 was still evaluating, and php_xpath_eval() wrote back into it once
the evaluation returned. The evaluation depth is now tracked on the object
and __construct() throws while it is non-zero.

Close phpGH-23735
The prompt parser ran as a do-while, so an empty cli.prompt executed
the body on the terminator and scanned past it. Use a while loop and
smart_str_extract(), which returns the interned empty string when
nothing was appended. No regression test: extra unicode warnings from
the over-read depend on heap contents, so a .phpt cannot pin the bug
red-before.

Closes phpGH-23415
init_process_info() memset the pointer parameter instead of the
PROCESS_INFORMATION structure it points at, leaving the struct
uninitialized before CreateProcessW(). Zero it through the pointer.

find_comspec_nt() dereferences *comspec in its cleanup while the
caller only assigns it on success, so a failed SearchPathW() read an
indeterminate value. Initialize the caller's variable to NULL.

set_proc_descriptor_to_blackhole() tested CreateFileA() against NULL,
but CreateFileA() signals failure with INVALID_HANDLE_VALUE, so a
failed open went undetected and an invalid handle was inherited by
the child. Test against INVALID_HANDLE_VALUE.

Closes phpGH-23412
…tructions with callable conversion

Call level counter was broken: ZEND_CALLABLE_CONVERT was forgotten.

Closes phpGH-23777.
The x86 matcher folds v = BINOP(a, b); c = CMP(v, 0); GUARD(c) into
IR_GUARD_JCC_INT, emitting the BINOP, dropping the CMP and branching on
the flags the BINOP left, but it only required the BINOP to precede the
CMP in the IR. Once GCM hoists a loop-invariant BINOP into a dominating
block, the jcc reads flags the intervening code has clobbered and the
guard fires on whatever is in EFLAGS. Require the BINOP to sit in the
guard's block and allow only snapshots between the comparison and the
guard, the way ir_match_fuse_load() pairs ir_in_same_block() with
ir_match_has_mem_deps(). The sibling MEM_BINOP fold already checks the
block, the IF side folds are pinned by full ref adjacency, and
ir_aarch64.dasc has no guard fold.

Mirrors the upstream fix dstogov/ir@51107a3.

Fixes phpGH-23693
Closes phpGH-23711
The answer loop read type, class, ttl, rdlength and weight with raw
GETSHORT() after an unvalidated dn_skipname() advance, so a reply whose
last record name ends at the end of the received data read up to about 12
bytes past the 64K querybuf stack union, with the weight reaching userland
through the $weights array. Guard the fixed-size header fields the way
php_parserr() already does; rdata skips stay bounded by the cp < end loop
condition.
@iliaal
iliaal force-pushed the fix/dns-getmx-checkcp-84 branch from 4e5759c to 70bc729 Compare September 20, 2026 16:11
@iliaal

iliaal commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php#23798.

@iliaal iliaal closed this Sep 20, 2026
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.

4 participants