jani            Tue May 26 15:49:15 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/curl   interface.c php_curl.h 
  Log:
  MFH: Fixed bug #48203 (crash when CURLOPT_STDERR is set to regular file)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/curl/interface.c?r1=1.62.2.14.2.27.2.49&r2=1.62.2.14.2.27.2.50&diff_format=u
Index: php-src/ext/curl/interface.c
diff -u php-src/ext/curl/interface.c:1.62.2.14.2.27.2.49 
php-src/ext/curl/interface.c:1.62.2.14.2.27.2.50
--- php-src/ext/curl/interface.c:1.62.2.14.2.27.2.49    Thu May 21 12:52:05 2009
+++ php-src/ext/curl/interface.c        Tue May 26 15:49:15 2009
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: interface.c,v 1.62.2.14.2.27.2.49 2009/05/21 12:52:05 iliaa Exp $ */
+/* $Id: interface.c,v 1.62.2.14.2.27.2.50 2009/05/26 15:49:15 jani Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -459,7 +459,7 @@
        le_curl_multi_handle = 
zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl", 
module_number);
 
        /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
-          or curl src/docs/libcurl/symbols-in-versions for a (almost) complete 
list 
+          or curl src/docs/libcurl/symbols-in-versions for a (almost) complete 
list
           of options and which version they were introduced */
 
        /* Constants for curl_setopt() */
@@ -1673,6 +1673,20 @@
                                        ch->handlers->read->fp = fp;
                                        ch->handlers->read->fd = 
Z_LVAL_PP(zvalue);
                                        break;
+                               case CURLOPT_STDERR:
+                                       if (((php_stream *) what)->mode[0] != 
'r') {
+                                               if (ch->handlers->stderr) {
+                                                       
zval_ptr_dtor(&ch->handlers->stderr);
+                                               }
+                                               zval_add_ref(zvalue);
+                                               ch->handlers->stderr = *zvalue;
+                                               
zend_list_addref(Z_LVAL_PP(zvalue));
+                                       } else {
+                                               php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
+                                               RETVAL_FALSE;
+                                               return 1;
+                                       }
+                                       /* break omitted intentionally */
                                default:
                                        error = curl_easy_setopt(ch->cp, 
option, fp);
                                        break;
@@ -2268,6 +2282,11 @@
        fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
 #endif
 
+       /* Prevent crash inside cURL if passed file has already been closed */
+       if (ch->handlers->stderr && Z_REFCOUNT_P(ch->handlers->stderr) <= 0) {
+               curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
+       }
+
        curl_easy_cleanup(ch->cp);
 #if LIBCURL_VERSION_NUM < 0x071101
        zend_llist_clean(&ch->to_free.str);
@@ -2287,12 +2306,15 @@
        if (ch->handlers->write_header->func_name) {
                zval_ptr_dtor(&ch->handlers->write_header->func_name);
        }
-       if(ch->handlers->progress->func_name) {
+       if (ch->handlers->progress->func_name) {
                zval_ptr_dtor(&ch->handlers->progress->func_name);
        }
        if (ch->handlers->passwd) {
                zval_ptr_dtor(&ch->handlers->passwd);
        }
+       if (ch->handlers->stderr) {
+               zval_ptr_dtor(&ch->handlers->stderr);
+       }
        if (ch->header.str_len > 0) {
                efree(ch->header.str);
        }
http://cvs.php.net/viewvc.cgi/php-src/ext/curl/php_curl.h?r1=1.44.2.2.2.2.2.4&r2=1.44.2.2.2.2.2.5&diff_format=u
Index: php-src/ext/curl/php_curl.h
diff -u php-src/ext/curl/php_curl.h:1.44.2.2.2.2.2.4 
php-src/ext/curl/php_curl.h:1.44.2.2.2.2.2.5
--- php-src/ext/curl/php_curl.h:1.44.2.2.2.2.2.4        Sun May  3 14:59:46 2009
+++ php-src/ext/curl/php_curl.h Tue May 26 15:49:15 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_curl.h,v 1.44.2.2.2.2.2.4 2009/05/03 14:59:46 pajoye Exp $ */
+/* $Id: php_curl.h,v 1.44.2.2.2.2.2.5 2009/05/26 15:49:15 jani Exp $ */
 
 #ifndef _PHP_CURL_H
 #define _PHP_CURL_H
@@ -107,6 +107,7 @@
        php_curl_write *write_header;
        php_curl_read  *read;
        zval           *passwd;
+       zval           *stderr;
        php_curl_progress *progress;
 } php_curl_handlers;
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to