Skip to content

Fix GH-25954: dns_get_mx() parses MX exchange past the record RDATA - #25986

Open
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-25954
Open

lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-25954

Conversation

@lazerg

@lazerg lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

dns_get_mx() expanded the MX exchange with dn_expand() bounded by the end of the whole message, not the end of the record's RDATA. An exchange name with no terminating label ran on into the next record, so its owner name ended up in $hosts. The fixed RR header and the preference were also read without checking that they fit in the reply.

The exchange is now expanded up to the end of the RDATA, and the header, RDLENGTH and preference are checked against the reply length. A malformed MX record makes dns_get_mx() return false, the same as when dn_expand() already failed. Tested in a debian container against the crafted UDP server from the issue; a well-formed reply with compressed exchange names still returns the same result. No .phpt, since the BIND-based tests in ext/standard/tests/dns cannot serve a malformed record.

Fixes #25954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant