@@ -105,7 +105,7 @@ static ZEND_ATTRIBUTE_UNUSED unsigned long php_curl_ssl_id(void)
105105
106106static zend_result php_curl_option_str (php_curl * ch , zend_long option , const char * str , const size_t len )
107107{
108- if (strlen (str ) != len ) {
108+ if (zend_char_has_nul_byte (str , len ) ) {
109109 zend_value_error ("%s(): cURL option must not contain any null bytes" , get_active_function_name ());
110110 return FAILURE ;
111111 }
@@ -116,25 +116,29 @@ static zend_result php_curl_option_str(php_curl *ch, zend_long option, const cha
116116 return error == CURLE_OK ? SUCCESS : FAILURE ;
117117}
118118
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 ) /* {{{ */
120120{
121121 /* Disable file:// if open_basedir are used */
122122 if (PG (open_basedir ) && * PG (open_basedir )) {
123123 curl_easy_setopt (ch -> cp , CURLOPT_PROTOCOLS , CURLPROTO_ALL & ~CURLPROTO_FILE );
124124 }
125125
126126#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+ ) {
128132 char _tmp [MAXPATHLEN ] = {0 };
129133
130134 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 );
132136
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 );
134138 }
135139#endif
136140
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 ) );
138142}
139143/* }}} */
140144
@@ -1143,7 +1147,7 @@ PHP_FUNCTION(curl_init)
11431147 _php_curl_set_default_options (ch );
11441148
11451149 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 ) {
11471151 zval_ptr_dtor (return_value );
11481152 RETURN_FALSE ;
11491153 }
@@ -1952,7 +1956,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
19521956 {
19531957 zend_string * tmp_str ;
19541958 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 );
19561960 zend_tmp_string_release (tmp_str );
19571961 return ret ;
19581962 }
0 commit comments