php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #54798
Patch fix-bug54798 revision 2011-05-17 14:26 UTC by confik at gmail dot com

Patch fix-bug54798 for cURL related Bug #54798

Patch version 2011-05-17 14:26 UTC

Return to Bug #54798 | Download this patch
Patch Revisions:

Developer: confik@gmail.com

Index: trunk/ext/curl/interface.c
===================================================================
--- trunk/ext/curl/interface.c	(revision 311121)
+++ trunk/ext/curl/interface.c	(working copy)
@@ -2204,6 +2204,16 @@
 
 	ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
 
+	// check if custom std_err is not already closed
+	if (ch->handlers->std_err) {
+		php_stream *stream;
+
+	    if (!(php_stream_from_zval_no_verify(stream, &ch->handlers->std_err))) {
+	        php_error_docref(NULL TSRMLS_CC, E_WARNING, "STDERR file handle is incorrect");
+	        curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
+	    }
+	}
+
 	_php_curl_cleanup_handle(ch);
 
 	error = curl_easy_perform(ch->cp);
Index: trunk/ext/curl/tests/bug48203.phpt
===================================================================
--- trunk/ext/curl/tests/bug48203.phpt	(revision 311121)
+++ trunk/ext/curl/tests/bug48203.phpt	(working copy)
@@ -18,16 +18,23 @@
 
 curl_setopt($ch, CURLOPT_VERBOSE, 1);
 curl_setopt($ch, CURLOPT_STDERR, $fp);
-curl_setopt($ch, CURLOPT_URL, "");
+curl_setopt($ch, CURLOPT_URL, getenv("PHP_CURL_HTTP_REMOTE_SERVER"));
 
 fclose($fp); // <-- premature close of $fp caused a crash!
 
 curl_exec($ch);
 
+curl_close($ch);
+
 echo "Ok\n";
 
 ?>
 --CLEAN--
 <?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
---EXPECT--
+--EXPECTF--
+Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
+
+Warning: curl_exec(): STDERR file handle is incorrect in %s on line %d
+* About to connect() %a
+* Closing connection #0
 Ok
Index: branches/PHP_5_3/ext/curl/interface.c
===================================================================
--- branches/PHP_5_3/ext/curl/interface.c	(revision 311132)
+++ branches/PHP_5_3/ext/curl/interface.c	(working copy)
@@ -2208,6 +2208,16 @@
 
 	ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
 
+	// check if custom std_err is not already closed
+	if (ch->handlers->std_err) {
+		php_stream *stream;
+
+	    if (!(php_stream_from_zval_no_verify(stream, &ch->handlers->std_err))) {
+	        php_error_docref(NULL TSRMLS_CC, E_WARNING, "STDERR file handle is incorrect");
+	        curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
+	    }
+	}
+
 	_php_curl_cleanup_handle(ch);
 
 	error = curl_easy_perform(ch->cp);
Index: branches/PHP_5_3/ext/curl/tests/bug48203.phpt
===================================================================
--- branches/PHP_5_3/ext/curl/tests/bug48203.phpt	(revision 311132)
+++ branches/PHP_5_3/ext/curl/tests/bug48203.phpt	(working copy)
@@ -18,16 +18,23 @@
 
 curl_setopt($ch, CURLOPT_VERBOSE, 1);
 curl_setopt($ch, CURLOPT_STDERR, $fp);
-curl_setopt($ch, CURLOPT_URL, "");
+curl_setopt($ch, CURLOPT_URL, getenv("PHP_CURL_HTTP_REMOTE_SERVER"));
 
 fclose($fp); // <-- premature close of $fp caused a crash!
 
 curl_exec($ch);
 
+curl_close($ch);
+
 echo "Ok\n";
 
 ?>
 --CLEAN--
 <?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
---EXPECT--
+--EXPECTF--
+Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
+
+Warning: curl_exec(): STDERR file handle is incorrect in %s on line %d
+* About to connect() %a
+* Closing connection #0
 Ok
Index: branches/PHP_5_4/ext/curl/interface.c
===================================================================
--- branches/PHP_5_4/ext/curl/interface.c	(revision 311121)
+++ branches/PHP_5_4/ext/curl/interface.c	(working copy)
@@ -2204,6 +2204,16 @@
 
 	ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
 
+	// check if custom std_err is not already closed
+	if (ch->handlers->std_err) {
+		php_stream *stream;
+
+	    if (!(php_stream_from_zval_no_verify(stream, &ch->handlers->std_err))) {
+	        php_error_docref(NULL TSRMLS_CC, E_WARNING, "STDERR file handle is incorrect");
+	        curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
+	    }
+	}
+
 	_php_curl_cleanup_handle(ch);
 
 	error = curl_easy_perform(ch->cp);
Index: branches/PHP_5_4/ext/curl/tests/bug48203.phpt
===================================================================
--- branches/PHP_5_4/ext/curl/tests/bug48203.phpt	(revision 311121)
+++ branches/PHP_5_4/ext/curl/tests/bug48203.phpt	(working copy)
@@ -18,16 +18,23 @@
 
 curl_setopt($ch, CURLOPT_VERBOSE, 1);
 curl_setopt($ch, CURLOPT_STDERR, $fp);
-curl_setopt($ch, CURLOPT_URL, "");
+curl_setopt($ch, CURLOPT_URL, getenv("PHP_CURL_HTTP_REMOTE_SERVER"));
 
 fclose($fp); // <-- premature close of $fp caused a crash!
 
 curl_exec($ch);
 
+curl_close($ch);
+
 echo "Ok\n";
 
 ?>
 --CLEAN--
 <?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
---EXPECT--
+--EXPECTF--
+Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
+
+Warning: curl_exec(): STDERR file handle is incorrect in %s on line %d
+* About to connect() %a
+* Closing connection #0
 Ok
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC