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

ext/curl/interface.c

index 89a3c6c3bb59d98ef3ec593986b772542f74b4d3..c814fa0e83a5e122e6a12bc4e863b6a668198a4e 100644 (file)
@@ -1649,12 +1649,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));