Repository navigation
Implement null byte checks for hostnames and addresses #24770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
|
||
|
|
@@ -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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not seeing the change. |
||
| return FAILURE; | ||
| } | ||
|
|
||
| if (*addr == '[') { | ||
| colon = memchr(addr + 1, ']', addrlen-1); | ||
| if (!colon || colon[1] != ':') { | ||
|
|
||
There was a problem hiding this comment.
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.