]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #48207 (CURLOPT_(FILE|WRITEHEADER options do not error out
authorIlia Alshanetsky <iliaa@php.net>
Thu, 21 May 2009 12:53:24 +0000 (12:53 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 21 May 2009 12:53:24 +0000 (12:53 +0000)
when working with a non-writable stream)

NEWS
ext/curl/interface.c

diff --git a/NEWS b/NEWS
index 5c73ecd42bb03f6051e539a42c95d609c79265f7..b6714bf6318b6e80f797abc407d7ca000fa0f7db 100644 (file)
--- 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
index 1bacf9ea35a84916526f2183fe841647cd53bd25..ffea78e7a65a2bc809e1cc856f0df30fe9fd4d1a 100644 (file)
@@ -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));