@@ -459,7 +459,7 @@ PHP_MINIT_FUNCTION(curl)
459
459
le_curl_multi_handle = zend_register_list_destructors_ex (_php_curl_multi_close , NULL , "curl" , module_number );
460
460
461
461
/* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
462
- or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
462
+ or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
463
463
of options and which version they were introduced */
464
464
465
465
/* Constants for curl_setopt() */
@@ -1673,6 +1673,20 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
1673
1673
ch -> handlers -> read -> fp = fp ;
1674
1674
ch -> handlers -> read -> fd = Z_LVAL_PP (zvalue );
1675
1675
break ;
1676
+ case CURLOPT_STDERR :
1677
+ if (((php_stream * ) what )-> mode [0 ] != 'r' ) {
1678
+ if (ch -> handlers -> stderr ) {
1679
+ zval_ptr_dtor (& ch -> handlers -> stderr );
1680
+ }
1681
+ zval_add_ref (zvalue );
1682
+ ch -> handlers -> stderr = * zvalue ;
1683
+ zend_list_addref (Z_LVAL_PP (zvalue ));
1684
+ } else {
1685
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "the provided file handle is not writable" );
1686
+ RETVAL_FALSE ;
1687
+ return 1 ;
1688
+ }
1689
+ /* break omitted intentionally */
1676
1690
default :
1677
1691
error = curl_easy_setopt (ch -> cp , option , fp );
1678
1692
break ;
@@ -2268,6 +2282,11 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
2268
2282
fprintf (stderr , "DTOR CALLED, ch = %x\n" , ch );
2269
2283
#endif
2270
2284
2285
+ /* Prevent crash inside cURL if passed file has already been closed */
2286
+ if (ch -> handlers -> stderr && Z_REFCOUNT_P (ch -> handlers -> stderr ) <= 0 ) {
2287
+ curl_easy_setopt (ch -> cp , CURLOPT_STDERR , stderr );
2288
+ }
2289
+
2271
2290
curl_easy_cleanup (ch -> cp );
2272
2291
#if LIBCURL_VERSION_NUM < 0x071101
2273
2292
zend_llist_clean (& ch -> to_free .str );
@@ -2287,12 +2306,15 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
2287
2306
if (ch -> handlers -> write_header -> func_name ) {
2288
2307
zval_ptr_dtor (& ch -> handlers -> write_header -> func_name );
2289
2308
}
2290
- if (ch -> handlers -> progress -> func_name ) {
2309
+ if (ch -> handlers -> progress -> func_name ) {
2291
2310
zval_ptr_dtor (& ch -> handlers -> progress -> func_name );
2292
2311
}
2293
2312
if (ch -> handlers -> passwd ) {
2294
2313
zval_ptr_dtor (& ch -> handlers -> passwd );
2295
2314
}
2315
+ if (ch -> handlers -> stderr ) {
2316
+ zval_ptr_dtor (& ch -> handlers -> stderr );
2317
+ }
2296
2318
if (ch -> header .str_len > 0 ) {
2297
2319
efree (ch -> header .str );
2298
2320
}
0 commit comments