Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions ext/standard/tests/url/bug79178.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Bug #79178 [parse_url] underscore at end of host
--FILE--
<?php

// Should return false because HOST contains a control character (PHP_EOL)
var_dump(parse_url('https://php.net' . PHP_EOL, PHP_URL_HOST));

?>
--EXPECT--
bool(false)
16 changes: 15 additions & 1 deletion ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,21 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
}

ret->host = zend_string_init(s, (p-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host));
char *host_str = ZSTR_VAL(ret->host);
size_t host_len = ZSTR_LEN(ret->host);

/* check for control characters and marks host as invalid if present */
unsigned char *current = (unsigned char *)host_str;
unsigned char *last = current + host_len;
while (current < last) {
if (iscntrl(*current)) {
php_url_free(ret);
return NULL;
}
current++;
}

php_replace_controlchars_ex(host_str, host_len);

if (e == ue) {
return ret;
Expand Down