From: Ilia Alshanetsky Date: Thu, 21 May 2009 12:53:24 +0000 (+0000) Subject: MFB: Fixed bug #48207 (CURLOPT_(FILE|WRITEHEADER options do not error out X-Git-Tag: php-5.2.10RC1~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c3d8accbbe1b7249b5706ca792603867041ef27;p=php MFB: Fixed bug #48207 (CURLOPT_(FILE|WRITEHEADER options do not error out when working with a non-writable stream) --- diff --git a/NEWS b/NEWS index 5c73ecd42b..b6714bf631 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ PHP NEWS - Fixed bug #48240 (DBA Segmentation fault dba_nextkey). (Felipe) - Fixed bug #48224 (Incorrect shuffle in array_rand). (Etienne) - Fixed bug #48221 (memory leak when passing invalid xslt parameter). (Felipe) +- Fixed bug #48207 (CURLOPT_(FILE|WRITEHEADER options do not error out when + working with a non-writable stream). (Ilia) - Fixed bug #48206 (Iterating over an invalid data structure with RecursiveIteratorIterator leads to a segfault). (Scott) - Fixed bug #48204 (xmlwriter_open_uri() does not emit warnings on invalid diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 1bacf9ea35..ffea78e7a6 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1436,12 +1436,24 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu error = CURLE_OK; switch (option) { case CURLOPT_FILE: - ch->handlers->write->fp = fp; - ch->handlers->write->method = PHP_CURL_FILE; + if (((php_stream *) what)->mode[0] != 'r') { + ch->handlers->write->fp = fp; + ch->handlers->write->method = PHP_CURL_FILE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); + RETVAL_FALSE; + return 1; + } break; case CURLOPT_WRITEHEADER: - ch->handlers->write_header->fp = fp; - ch->handlers->write_header->method = PHP_CURL_FILE; + if (((php_stream *) what)->mode[0] != 'r') { + ch->handlers->write_header->fp = fp; + ch->handlers->write_header->method = PHP_CURL_FILE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); + RETVAL_FALSE; + return 1; + } break; case CURLOPT_INFILE: zend_list_addref(Z_LVAL_PP(zvalue));