Skip to content

Fix GH-25137: Reject malformed SNMP ports - #25138

Open
somethingwithproof wants to merge 1 commit into
php:masterfrom
somethingwithproof:fix/snmp-strict-port-parsing
Open

somethingwithproof wants to merge 1 commit into
php:masterfrom
somethingwithproof:fix/snmp-strict-port-parsing

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25137.

Master already rejects remote ports outside 0..65535, but still parses them with atoi(), so an empty, nonnumeric or partially numeric suffix (host:, host:abc, host:123abc) is read as 0 or as its leading digits, and a long digit string overflows. This replaces atoi() with a parser that requires one or more decimal digits and nothing else, keeping the existing range and error message.

The new gh25137.phpt covers IPv4 and bracketed IPv6 hostnames, both range boundaries, an overflowing value, and the procedural and OO APIs. UPGRADING notes the stricter parsing.

Verification: clang debug build with ASan and UBSan. gh25137.phpt fails on master and passes with this change; all runnable ext/snmp tests pass.

@devnexen

devnexen commented Nov 2, 2026

Copy link
Copy Markdown
Member

Hi @somethingwithproof that looks like an improvement for master, that would need to focus on improving port checks that had been introduced in 8.5 IMHO.

The remote port suffix in an SNMP hostname was parsed with atoi(), so an
empty, nonnumeric or partially numeric suffix was read as 0 or as its
leading digits, and a long digit string overflowed. Require one or more
decimal digits and nothing else, keeping the existing 0..65535 range and
error message.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
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.

SNMP accepts malformed remote ports

2 participants