@@ -105,7 +105,7 @@ static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
105
105
106
106
static zend_result php_curl_option_str (php_curl * ch , zend_long option , const char * str , const size_t len )
107
107
{
108
- if (strlen (str ) != len ) {
108
+ if (zend_char_has_nul_byte (str , len ) ) {
109
109
zend_value_error ("%s(): cURL option must not contain any null bytes" , get_active_function_name ());
110
110
return FAILURE ;
111
111
}
@@ -116,25 +116,29 @@ static zend_result php_curl_option_str(php_curl *ch, zend_long option, const cha
116
116
return error == CURLE_OK ? SUCCESS : FAILURE ;
117
117
}
118
118
119
- static zend_result php_curl_option_url (php_curl * ch , const char * url , const size_t len ) /* {{{ */
119
+ static zend_result php_curl_option_url (php_curl * ch , const zend_string * url ) /* {{{ */
120
120
{
121
121
/* Disable file:// if open_basedir are used */
122
122
if (PG (open_basedir ) && * PG (open_basedir )) {
123
123
curl_easy_setopt (ch -> cp , CURLOPT_PROTOCOLS , CURLPROTO_ALL & ~CURLPROTO_FILE );
124
124
}
125
125
126
126
#if LIBCURL_VERSION_NUM > 0x073800 && defined(PHP_WIN32 )
127
- if (len > sizeof ("file://" ) - 1 && '/' != url [sizeof ("file://" ) - 1 ] && !strncmp ("file://" , url , sizeof ("file://" ) - 1 ) && len < MAXPATHLEN - 2 ) {
127
+ if (
128
+ zend_string_starts_with_literal_ci (url , "file://" )
129
+ && '/' != ZSTR_VAL (url )[sizeof ("file://" ) - 1 ]
130
+ && ZSTR_LEN (url ) < MAXPATHLEN - 2
131
+ ) {
128
132
char _tmp [MAXPATHLEN ] = {0 };
129
133
130
134
memmove (_tmp , "file:///" , sizeof ("file:///" ) - 1 );
131
- memmove (_tmp + sizeof ("file:///" ) - 1 , url + sizeof ("file://" ) - 1 , len - sizeof ("file://" ) + 1 );
135
+ memmove (_tmp + sizeof ("file:///" ) - 1 , ZSTR_VAL ( url ) + sizeof ("file://" ) - 1 , ZSTR_LEN ( url ) - sizeof ("file://" ) + 1 );
132
136
133
- return php_curl_option_str (ch , CURLOPT_URL , _tmp , len + 1 );
137
+ return php_curl_option_str (ch , CURLOPT_URL , _tmp , ZSTR_LEN ( url ) + 1 );
134
138
}
135
139
#endif
136
140
137
- return php_curl_option_str (ch , CURLOPT_URL , url , len );
141
+ return php_curl_option_str (ch , CURLOPT_URL , ZSTR_VAL ( url ), ZSTR_LEN ( url ) );
138
142
}
139
143
/* }}} */
140
144
@@ -1143,7 +1147,7 @@ PHP_FUNCTION(curl_init)
1143
1147
_php_curl_set_default_options (ch );
1144
1148
1145
1149
if (url ) {
1146
- if (php_curl_option_url (ch , ZSTR_VAL ( url ), ZSTR_LEN ( url ) ) == FAILURE ) {
1150
+ if (php_curl_option_url (ch , url ) == FAILURE ) {
1147
1151
zval_ptr_dtor (return_value );
1148
1152
RETURN_FALSE ;
1149
1153
}
@@ -1952,7 +1956,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
1952
1956
{
1953
1957
zend_string * tmp_str ;
1954
1958
zend_string * str = zval_get_tmp_string (zvalue , & tmp_str );
1955
- zend_result ret = php_curl_option_url (ch , ZSTR_VAL ( str ), ZSTR_LEN ( str ) );
1959
+ zend_result ret = php_curl_option_url (ch , str );
1956
1960
zend_tmp_string_release (tmp_str );
1957
1961
return ret ;
1958
1962
}
0 commit comments