Browse Source

fix bug #64247 (CURLOPT_INFILE doesn't allow reset)

PHP-5.5.13
Michael Wallner 12 years ago
parent
commit
54fee59598
  1. 3
      NEWS
  2. 68
      ext/curl/interface.c
  3. 18
      ext/curl/tests/bug54798.phpt
  4. 35
      ext/curl/tests/bug64267.phpt
  5. 2
      ext/curl/tests/curl_basic_008.phpt
  6. 2
      ext/curl/tests/curl_basic_010.phpt
  7. 3
      ext/curl/tests/curl_reset.phpt

3
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)

68
ext/curl/interface.c

@ -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);
}

18
ext/curl/tests/bug54798.phpt

@ -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===

35
ext/curl/tests/bug64267.phpt

@ -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===

2
ext/curl/tests/curl_basic_008.phpt

@ -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)

2
ext/curl/tests/curl_basic_010.phpt

@ -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)

3
ext/curl/tests/curl_reset.phpt

@ -36,5 +36,8 @@ unlink($test_file);
unlink($log_file);
?>
===DONE===
--EXPECT--
testtest
===DONE===
Loading…
Cancel
Save