Skip to content

Fix GH-25968: dns_get_record() reads A record bytes past a short RDATA - #25984

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

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

Conversation

@lazerg

@lazerg lazerg commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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.

Fixes #25968

@lazerg
lazerg requested a review from bukka as a code owner December 1, 2026 01:40
@lazerg lazerg changed the title [PHP-8.4] Fix GH-25968: dns_get_record() reads A record bytes past a short RDATA Fix GH-25968: dns_get_record() reads A record bytes past a short RDATA Dec 1, 2026

@devnexen devnexen left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine as-is eventually things can be a bit stricter (RFC-wise) on master in that regard, would not be high priority though IMO.

@bukka bukka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new testing setup so all dns.c changes should now have a test if possible.

@devnexen

devnexen commented Dec 1, 2026

Copy link
Copy Markdown
Member

ah good to know.

@lazerg

lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

I tried to add one with the BIND setup, but BIND refuses to load an A record with less than 4 bytes of RDATA. Even the generic \# 2 0102 form fails in named-checkzone with "unexpected end of input". So I tested the fix with the fake UDP server from the issue instead.

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.

dns_get_record(): A record with short RDATA publishes a wrong IP address (bytes taken from the next record)

3 participants