Skip to content

Commit 8aecb11

Browse files
authored
Implement null byte checks for hostnames and addresses
Added checks to reject hostnames and addresses containing null bytes to mitigate CVE-2025-1220.
1 parent 3b8e988 commit 8aecb11

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎main/network.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ PHPAPI int php_network_getaddresses(const char *host, int socktype, struct socka
156156
if (host == NULL) {
157157
return 0;
158158
}
159+
160+
/* CVE-2025-1220: reject hostnames containing null bytes */
161+
{
162+
size_t host_len = strlen(host);
163+
if (memchr(host, '\0', host_len) != NULL) {
164+
if (error_string) {
165+
*error_string = ZSTR_INIT_LITERAL("The hostname must not contain null bytes", 0);
166+
php_error_docref(NULL, E_WARNING, "%s", ZSTR_VAL(*error_string));
167+
} else {
168+
php_error_docref(NULL, E_WARNING, "The hostname must not contain null bytes");
169+
}
170+
return 0;
171+
}
172+
}
173+
159174
#ifdef HAVE_GETADDRINFO
160175
memset(&hints, '\0', sizeof(hints));
161176

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

655+
/* CVE-2025-1220: reject addresses containing null bytes */
656+
if (memchr(addr, '\0', addrlen) != NULL) {
657+
return FAILURE;
658+
}
659+
640660
if (*addr == '[') {
641661
colon = memchr(addr + 1, ']', addrlen-1);
642662
if (!colon || colon[1] != ':') {

0 commit comments

Comments
 (0)