Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions main/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka
if (host == NULL) {
return 0;
}

/* 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;
}
}
Comment on lines +160 to +172

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.

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.


#ifdef HAVE_GETADDRINFO
memset(&hints, '\0', sizeof(hints));

Expand Down Expand Up @@ -637,6 +652,11 @@ PHPAPI zend_result php_network_parse_network_address_with_port(const char *addr,
memset(in4, 0, sizeof(struct sockaddr_in));
#endif

/* CVE-2025-1220: reject addresses containing null bytes */
if (memchr(addr, '\0', addrlen) != NULL) {

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.

zend_char_has_nul_byte().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/* 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.

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.

Done — force-pushed with zend_char_has_nul_byte() instead of memchr(), as suggested.

Not seeing the change.

return FAILURE;
}

if (*addr == '[') {
colon = memchr(addr + 1, ']', addrlen-1);
if (!colon || colon[1] != ':') {
Expand Down
Loading