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;
}
}

#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) {
Comment thread
SleepTheGod marked this conversation as resolved.
return FAILURE;
}

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