]> granicus.if.org Git - php/commitdiff
fix bug #64247 (CURLOPT_INFILE doesn't allow reset)
authorMichael Wallner <mike@php.net>
Wed, 30 Apr 2014 07:26:50 +0000 (09:26 +0200)
committerMichael Wallner <mike@php.net>
Wed, 30 Apr 2014 07:27:58 +0000 (09:27 +0200)
NEWS
ext/curl/interface.c
ext/curl/tests/bug54798.phpt
ext/curl/tests/bug64267.phpt [new file with mode: 0644]
ext/curl/tests/curl_basic_008.phpt
ext/curl/tests/curl_basic_010.phpt
ext/curl/tests/curl_reset.phpt

diff --git a/NEWS b/NEWS
index 513442bfba87c02aab2536ccc89fddb83cc3a2ff..f52344c4a9a1d40218d77ca1947aea9e6249190f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ PHP                                                                        NEWS
     by tempnam()). (Boro Sitnikovski)
   . Fixed bug #67072 (Echoing unserialized "SplFileObject" crash). (Anatol)
 
+- Curl:
+  . Fixed bug #64247 (CURLOPT_INFILE doesn't allow reset). (Mike)
+
 - Date:
   . Fixed bug #67118 (DateTime constructor crash with invalid data). (Anatol)
 
index 87b871f2032b9b5a9c70fb4f9e15341879a1831d..765918cc3546ce1a1ed9c8697b234e01e3028834 100644 (file)
@@ -2351,25 +2351,34 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
                case CURLOPT_WRITEHEADER: {
                        FILE *fp = NULL;
                        int type;
-                       void * what;
+                       void *what = NULL;
 
-                       what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream());
-                       if (!what) {
-                               return FAILURE;
-                       }
+                       if (Z_TYPE_PP(zvalue) != IS_NULL) {
+                               what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream());
+                               if (!what) {
+                                       return FAILURE;
+                               }
 
-                       if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
-                               return FAILURE;
-                       }
+                               if (FAILURE == php_stream_cast((php_stream *) what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
+                                       return FAILURE;
+                               }
 
-                       if (!fp) {
-                               return FAILURE;
+                               if (!fp) {
+                                       return FAILURE;
+                               }
                        }
 
                        error = CURLE_OK;
                        switch (option) {
                                case CURLOPT_FILE:
-                                       if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
+                                       if (!what) {
+                                               if (ch->handlers->write->stream) {
+                                                       Z_DELREF_P(ch->handlers->write->stream);
+                                                       ch->handlers->write->stream = NULL;
+                                               }
+                                               ch->handlers->write->fp = NULL;
+                                               ch->handlers->write->method = PHP_CURL_STDOUT;
+                                       } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
                                                if (ch->handlers->write->stream) {
                                                        Z_DELREF_P(ch->handlers->write->stream);
                                                }
@@ -2383,7 +2392,14 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
                                        }
                                        break;
                                case CURLOPT_WRITEHEADER:
-                                       if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
+                                       if (!what) {
+                                               if (ch->handlers->write_header->stream) {
+                                                       Z_DELREF_P(ch->handlers->write_header->stream);
+                                                       ch->handlers->write_header->stream = NULL;
+                                               }
+                                               ch->handlers->write_header->fp = NULL;
+                                               ch->handlers->write_header->method = PHP_CURL_IGNORE;
+                                       } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
                                                if (ch->handlers->write_header->stream) {
                                                        Z_DELREF_P(ch->handlers->write_header->stream);
                                                }
@@ -2397,16 +2413,30 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
                                        }
                                        break;
                                case CURLOPT_INFILE:
-                                       if (ch->handlers->read->stream) {
-                                               Z_DELREF_P(ch->handlers->read->stream);
+                                       if (!what) {
+                                               if (ch->handlers->read->stream) {
+                                                       Z_DELREF_P(ch->handlers->read->stream);
+                                                       ch->handlers->read->stream = NULL;
+                                               }
+                                               ch->handlers->read->fp = NULL;
+                                               ch->handlers->read->fd = 0;
+                                       } else {
+                                               if (ch->handlers->read->stream) {
+                                                       Z_DELREF_P(ch->handlers->read->stream);
+                                               }
+                                               Z_ADDREF_PP(zvalue);
+                                               ch->handlers->read->fp = fp;
+                                               ch->handlers->read->fd = Z_LVAL_PP(zvalue);
+                                               ch->handlers->read->stream = *zvalue;
                                        }
-                                       Z_ADDREF_PP(zvalue);
-                                       ch->handlers->read->fp = fp;
-                                       ch->handlers->read->fd = Z_LVAL_PP(zvalue);
-                                       ch->handlers->read->stream = *zvalue;
                                        break;
                                case CURLOPT_STDERR:
-                                       if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
+                                       if (!what) {
+                                               if (ch->handlers->std_err) {
+                                                       zval_ptr_dtor(&ch->handlers->std_err);
+                                                       ch->handlers->std_err = NULL;
+                                               }
+                                       } else if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
                                                if (ch->handlers->std_err) {
                                                        zval_ptr_dtor(&ch->handlers->std_err);
                                                }
index f633a8ab2a44f2d9f992ff73ea8bdd482b36494c..afd98cb87e2f1f1b71df5f221fe802a7f954e7a9 100644 (file)
@@ -53,19 +53,13 @@ foreach($options_to_check as $option) {
 }
 
 ?>
+===DONE===
 --CLEAN--
 <?php @unlink(dirname(__FILE__) . '/bug54798.tmp'); ?>
 --EXPECTF--
-Warning: curl_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug54798.php on line %d
-* About to connect() %a
-* Closing connection %d
-Ok for CURLOPT_STDERR
-
-Warning: curl_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug54798.php on line 24
-Ok for CURLOPT_WRITEHEADER
-
-Warning: curl_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug54798.php on line 24
+%a
+%aOk for CURLOPT_STDERR
+%aOk for CURLOPT_WRITEHEADER
 %aOk for CURLOPT_FILE
-
-Warning: curl_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug54798.php on line %d
-Ok for CURLOPT_INFILE
+%aOk for CURLOPT_INFILE
+===DONE===
diff --git a/ext/curl/tests/bug64267.phpt b/ext/curl/tests/bug64267.phpt
new file mode 100644 (file)
index 0000000..3165b52
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #64267 (CURLOPT_INFILE doesn't allow reset)
+--SKIPIF--
+<?php
+extension_loaded("curl") or die("skip need ext/curl");
+?>
+--FILE--
+<?php
+
+echo "TEST\n";
+
+$c = curl_init("http://google.com");
+$f = fopen(__FILE__,"r");
+var_dump(curl_setopt_array($c, [
+       CURLOPT_RETURNTRANSFER => true,
+       CURLOPT_UPLOAD => true,
+       CURLOPT_INFILE => $f,
+       CURLOPT_INFILESIZE => filesize(__FILE__)
+]));
+fclose($f);
+var_dump(curl_setopt_array($c, [
+       CURLOPT_UPLOAD => false,
+       CURLOPT_INFILE => null,
+       CURLOPT_INFILESIZE => 0,
+]));
+curl_exec($c);
+var_dump(curl_getinfo($c, CURLINFO_RESPONSE_CODE));
+?>
+===DONE===
+--EXPECT--
+TEST
+bool(true)
+bool(true)
+int(302)
+===DONE===
index 29e3343707ebb05c1a4fa425ead0d5eb466a1675..4f0a29d7ff494e9a865f054250d379e4e022de25 100644 (file)
@@ -25,5 +25,5 @@ curl_close($ch);
 
 ?>
 --EXPECTF--
-%unicode|string%(%d) "%r(Couldn't resolve host|Could not resolve host:)%r %Swww.%s"
+%s resolve%s
 int(6)
index 0fc2fe6656c89de687cbe7b76fca85f9027309fb..72a591ff169cab6fd8bb764b268bbed5d4147347 100644 (file)
@@ -26,5 +26,5 @@ curl_close($ch);
 
 ?>
 --EXPECTF--
-%unicode|string%(%d) "%r(Couldn't resolve proxy|Could not resolve proxy:|Could not resolve host:)%r %s"
+%unicode|string%(%d) "%r(Couldn't resolve proxy|Could not resolve proxy:|Could not resolve host:|Could not resolve:)%r %s"
 int(5)
index c78a8e0953b6253df9f4360544e00eb137bc4b8a..3572e69543f2d177ff81df27987611244eb0794e 100644 (file)
@@ -36,5 +36,8 @@ unlink($test_file);
 unlink($log_file);
 
 ?>
+
+===DONE===
 --EXPECT--
 testtest
+===DONE===