php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch reset_to_default_with_multi.patch.txt for cURL related Bug #48203

Patch version 2011-06-09 07:31 UTC

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

Developer: shein@php.net

Index: trunk/ext/curl/php_curl.h
===================================================================
--- trunk/ext/curl/php_curl.h	(revision 306938)
+++ trunk/ext/curl/php_curl.h	(revision )
@@ -150,6 +150,7 @@
 
 void _php_curl_cleanup_handle(php_curl *);
 void _php_curl_multi_cleanup_list(void *data);
+int  _php_curl_file_pointers_correct(php_curl *ch TSRMLS_DC);
 
 /* streams support */
 
Index: trunk/ext/curl/multi.c
===================================================================
--- trunk/ext/curl/multi.c	(revision 306938)
+++ trunk/ext/curl/multi.c	(revision )
@@ -130,6 +130,16 @@
 }
 /* }}} */
 
+static long _php_curl_multi_remove_handle(php_curlm *mh, php_curl *ch)
+{
+	--ch->uses;
+
+	zend_llist_del_element( &mh->easyh, &ch,
+							(int (*)(void *, void *)) curl_compare_resources );
+
+	return (long) curl_multi_remove_handle(mh->multi, ch->cp);
+}
+
 /* {{{ proto int curl_multi_remove_handle(resource mh, resource ch)
    Remove a multi handle from a set of cURL handles */
 PHP_FUNCTION(curl_multi_remove_handle)
@@ -146,12 +156,7 @@
 	ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle);
 	ZEND_FETCH_RESOURCE(ch, php_curl *, &z_ch, -1, le_curl_name, le_curl);
 
-	--ch->uses;
-
-	zend_llist_del_element( &mh->easyh, &z_ch, 
-							(int (*)(void *, void *)) curl_compare_resources );
-	
-	RETURN_LONG((long) curl_multi_remove_handle(mh->multi, ch->cp));
+	RETURN_LONG(_php_curl_multi_remove_handle(mh, ch));
 }
 /* }}} */
 
@@ -211,6 +216,22 @@
 
 	ZEND_FETCH_RESOURCE(mh, php_curlm *, &z_mh, -1, le_curl_multi_handle_name, le_curl_multi_handle);
 
+	{
+		zend_llist_position pos;
+		php_curl *ch;
+		zval *ch_zval;
+
+		/* search the list of easy handles hanging off the multi-handle */
+		for(ch_zval = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); ch_zval;
+			ch_zval = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
+			ZEND_FETCH_RESOURCE(ch, php_curl *, &ch_zval, -1, le_curl_name, le_curl);
+
+			if (!_php_curl_file_pointers_correct(ch TSRMLS_CC)) {
+				_php_curl_multi_remove_handle(mh, ch);
+			}
+		}
+	}
+
 	convert_to_long_ex(&z_still_running);
 	still_running = Z_LVAL_P(z_still_running);
 	result = curl_multi_perform(mh->multi, &still_running);
Index: trunk/ext/curl/interface.c
===================================================================
--- trunk/ext/curl/interface.c	(revision 309881)
+++ trunk/ext/curl/interface.c	(revision )
@@ -2190,6 +2190,41 @@
 }
 /* }}} */
 
+int _php_curl_check_file_pointer(zval *zv_stream, const char* filehandle_type TSRMLS_DC)
+{
+	php_stream *stream;
+	if (zv_stream) {
+		if (!(php_stream_from_zval_no_verify(stream, &zv_stream))) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s handle is incorrect", filehandle_type);
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
+int _php_curl_file_pointers_correct(php_curl *ch TSRMLS_DC)
+{
+	if (!_php_curl_check_file_pointer(ch->handlers->std_err, "CURLOPT_STDERR" TSRMLS_CC)) {
+		curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
+	}
+
+	if (!_php_curl_check_file_pointer(ch->handlers->write->stream, "CURLOPT_FILE" TSRMLS_CC)) {
+		ch->handlers->write->method = PHP_CURL_STDOUT;
+	}
+
+	if (!_php_curl_check_file_pointer(ch->handlers->write_header->stream, "CURLOPT_WRITEHEADER" TSRMLS_CC)) {
+		ch->handlers->write_header->method = PHP_CURL_IGNORE;
+	}
+
+	// this is critical since there's no point in upload with corrupted file
+	if (!_php_curl_check_file_pointer(ch->handlers->read->stream, "CURLOPT_INFILE" TSRMLS_CC)) {
+		return 0;
+	}
+
+	return 1;
+}
+
 /* {{{ proto bool curl_exec(resource ch)
    Perform a cURL session */
 PHP_FUNCTION(curl_exec)
@@ -2204,6 +2239,10 @@
 
 	ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
 
+	if (!_php_curl_file_pointers_correct(ch TSRMLS_CC)) {
+		RETURN_FALSE;
+	}
+
 	_php_curl_cleanup_handle(ch);
 
 	error = curl_easy_perform(ch->cp);
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 05:03:19 2014 UTC