Repository navigation
Implement null byte checks for hostnames and addresses - #24770
SleepTheGod wants to merge 1 commit into
Conversation
Added checks to reject hostnames and addresses containing null bytes to mitigate CVE-2025-1220.
|
all checks passed |
|
it would be nice to add a test that would trigger the issue without your fix ... if the issue still occur. |
nope I ran this on current master without the patch, and the null byte is already rejected everywhere: That's already fixed by 5ef0dc7 (GHSA-3cr5-j632-f35r = CVE-2025-1220). The new check in |
|
Thanks @ArtUkrainskiy and @devnexen — you're both right, and I want to be explicit about what's happening here so we don't merge dead code. The
The real fix is already in the callers. CVE-2025-1220 was fixed in I'm dropping that hunk from this PR. The one part of the patch that is not dead is the check in Force-pushed to remove the unreachable |
|
Pulling this back to what actually needs fixing in this PR, and what shouldn't be here at all. Keep — the
|
| #endif | ||
|
|
||
| /* CVE-2025-1220: reject addresses containing null bytes */ | ||
| if (memchr(addr, '\0', addrlen) != NULL) { |
There was a problem hiding this comment.
/* CVE-2025-1220: reject addresses containing null bytes */
if (zend_char_has_nul_byte(addr, addrlen)) {
return FAILURE;
}Done — force-pushed with zend_char_has_nul_byte() instead of memchr(), as suggested. This PR now contains only the php_network_parse_network_address_with_port() defense-in-depth hunk; the unreachable php_network_getaddresses() block is gone. Ready for re-review when you have a moment. Thanks for the pointer.
There was a problem hiding this comment.
Done — force-pushed with
zend_char_has_nul_byte()instead ofmemchr(), as suggested.
Not seeing the change.
|
Done — switched to Thanks for the review, @TimWolla. |
| /* CVE-2025-1220: reject hostnames containing null bytes */ | ||
| { | ||
| size_t host_len = strlen(host); | ||
| if (memchr(host, '\0', host_len) != NULL) { | ||
| if (error_string) { | ||
| *error_string = ZSTR_INIT_LITERAL("The hostname must not contain null bytes", 0); | ||
| php_error_docref(NULL, E_WARNING, "%s", ZSTR_VAL(*error_string)); | ||
| } else { | ||
| php_error_docref(NULL, E_WARNING, "The hostname must not contain null bytes"); | ||
| } | ||
| return 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
This is utterly pointless and wrong.
strlen() will stop at first null byte, so trying to determine if a null byte exists is utterly nonsensical.
So for this to male any sense, the length would need to be provided to the function and every call site would need to be amended to do the same.
Added checks to reject hostnames and addresses containing null bytes to mitigate CVE-2025-1220.