Skip to content

ext/curl: Protocol should be a case insensitive check #11052

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

Merged
merged 1 commit into from
Apr 11, 2023
Merged
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: 12 additions & 8 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)

static zend_result php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len)
{
if (strlen(str) != len) {
if (zend_char_has_nul_byte(str, len)) {
zend_value_error("%s(): cURL option must not contain any null bytes", get_active_function_name());
return FAILURE;
}
Expand All @@ -116,25 +116,29 @@ static zend_result php_curl_option_str(php_curl *ch, zend_long option, const cha
return error == CURLE_OK ? SUCCESS : FAILURE;
}

static zend_result php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */
static zend_result php_curl_option_url(php_curl *ch, const zend_string *url) /* {{{ */
{
/* Disable file:// if open_basedir are used */
if (PG(open_basedir) && *PG(open_basedir)) {
curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
}

#if LIBCURL_VERSION_NUM > 0x073800 && defined(PHP_WIN32)
if (len > sizeof("file://") - 1 && '/' != url[sizeof("file://") - 1] && !strncmp("file://", url, sizeof("file://") - 1) && len < MAXPATHLEN - 2) {
if (
zend_string_starts_with_literal_ci(url, "file://")
&& '/' != ZSTR_VAL(url)[sizeof("file://") - 1]
&& ZSTR_LEN(url) < MAXPATHLEN - 2
) {
char _tmp[MAXPATHLEN] = {0};

memmove(_tmp, "file:///", sizeof("file:///") - 1);
memmove(_tmp + sizeof("file:///") - 1, url + sizeof("file://") - 1, len - sizeof("file://") + 1);
memmove(_tmp + sizeof("file:///") - 1, ZSTR_VAL(url) + sizeof("file://") - 1, ZSTR_LEN(url) - sizeof("file://") + 1);

return php_curl_option_str(ch, CURLOPT_URL, _tmp, len + 1);
return php_curl_option_str(ch, CURLOPT_URL, _tmp, ZSTR_LEN(url) + 1);
}
#endif

return php_curl_option_str(ch, CURLOPT_URL, url, len);
return php_curl_option_str(ch, CURLOPT_URL, ZSTR_VAL(url), ZSTR_LEN(url));
}
/* }}} */

Expand Down Expand Up @@ -1143,7 +1147,7 @@ PHP_FUNCTION(curl_init)
_php_curl_set_default_options(ch);

if (url) {
if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) {
if (php_curl_option_url(ch, url) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_FALSE;
}
Expand Down Expand Up @@ -1952,7 +1956,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
{
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
zend_result ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
zend_result ret = php_curl_option_url(ch, str);
zend_tmp_string_release(tmp_str);
return ret;
}
Expand Down