From c58d9568ff07bb9b308b971b8856fa7f54fb0b05 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Tue, 19 Feb 2013 22:53:07 +0100 Subject: [PATCH 1/3] ext/curl/interface.c: curl_setopt(CURLOPT_INFILE) allows to pass IS_NULL to reset INFILE to default, unless the read-function is a user callback Closes bug #64247 and #44866 --- ext/curl/interface.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 5bd1b479e21f..2a331a069454 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2371,6 +2371,22 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu int type; void * what; + //If a NULL was supplied together with INFILE, reset the default if we're still at direct i/o and don't have a user-function for read + if(Z_TYPE_PP(zvalue) == IS_NULL && option == CURLOPT_INFILE && ch->handlers->read->method == PHP_CURL_DIRECT) { + if(ch->handlers->read->stream != NULL) { + //Manually free if rc=0; if we don't do this, memory allocator will complain about leak + if(Z_REFCOUNT_P(ch->handlers->read->stream)==1) + zval_ptr_dtor(&ch->handlers->read->stream); + else + Z_DELREF_P(ch->handlers->read->stream); + } + ch->handlers->read->fd = 0; + ch->handlers->read->fp = 0; + ch->handlers->read->stream = NULL; + error = curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); + break; + } + what = zend_fetch_resource(zvalue TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream(), php_file_le_pstream()); if (!what) { RETVAL_FALSE; From 393078324e4d388729e13a67e34ff1964bee7aa3 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Tue, 19 Feb 2013 23:32:38 +0100 Subject: [PATCH 2/3] ext/curl/interface.c: use zval_ptr_dtor directly --- ext/curl/interface.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 2a331a069454..c2de5abb0e29 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2374,11 +2374,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu //If a NULL was supplied together with INFILE, reset the default if we're still at direct i/o and don't have a user-function for read if(Z_TYPE_PP(zvalue) == IS_NULL && option == CURLOPT_INFILE && ch->handlers->read->method == PHP_CURL_DIRECT) { if(ch->handlers->read->stream != NULL) { - //Manually free if rc=0; if we don't do this, memory allocator will complain about leak - if(Z_REFCOUNT_P(ch->handlers->read->stream)==1) - zval_ptr_dtor(&ch->handlers->read->stream); - else - Z_DELREF_P(ch->handlers->read->stream); + zval_ptr_dtor(&ch->handlers->read->stream); } ch->handlers->read->fd = 0; ch->handlers->read->fp = 0; From 65049d15c7ba13328acaca77e727a24faf893e07 Mon Sep 17 00:00:00 2001 From: Marco Schuster Date: Sat, 23 Feb 2013 20:13:04 +0100 Subject: [PATCH 3/3] ext/curl/interface.c: convert comments to /* */ style --- ext/curl/interface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index c2de5abb0e29..780592b1850f 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2371,7 +2371,8 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu int type; void * what; - //If a NULL was supplied together with INFILE, reset the default if we're still at direct i/o and don't have a user-function for read + /* If a NULL was supplied together with INFILE, reset the default if we're still at direct i/o and don't have a user-function for read */ + /* TODO: Allow setting to NULL for other combinations */ if(Z_TYPE_PP(zvalue) == IS_NULL && option == CURLOPT_INFILE && ch->handlers->read->method == PHP_CURL_DIRECT) { if(ch->handlers->read->stream != NULL) { zval_ptr_dtor(&ch->handlers->read->stream);