[PHP-CVS] cvs: php-src(PHP_5_2) / NEWS /ext/curl interface.c php_curl.h

2009-05-26 Thread Jani Taskinen
janiTue May 26 15:50:44 2009 UTC

  Modified files:  (Branch: PHP_5_2)
/php-srcNEWS 
/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/NEWS?r1=1.2027.2.547.2.1523r2=1.2027.2.547.2.1524diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1523 php-src/NEWS:1.2027.2.547.2.1524
--- php-src/NEWS:1.2027.2.547.2.1523Tue May 26 14:38:34 2009
+++ php-src/NEWSTue May 26 15:50:43 2009
@@ -37,6 +37,7 @@
   with RecursiveIteratorIterator leads to a segfault). (Scott)
 - Fixed bug #48204 (xmlwriter_open_uri() does not emit warnings on invalid
   paths). (Ilia)
+- Fixed bug #48203 (Crash when CURLOPT_STDERR is set to regular file). (Jani)
 - Fixed bug #48202 (Out of Memory error message when passing invalid file path)
   (Pierre)
 - Fixed bug #48156 (Added support for lcov v1.7). (Ilia)
http://cvs.php.net/viewvc.cgi/php-src/ext/curl/interface.c?r1=1.62.2.14.2.50r2=1.62.2.14.2.51diff_format=u
Index: php-src/ext/curl/interface.c
diff -u php-src/ext/curl/interface.c:1.62.2.14.2.50 
php-src/ext/curl/interface.c:1.62.2.14.2.51
--- php-src/ext/curl/interface.c:1.62.2.14.2.50 Thu May 21 12:53:24 2009
+++ php-src/ext/curl/interface.cTue May 26 15:50:44 2009
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: interface.c,v 1.62.2.14.2.50 2009/05/21 12:53:24 iliaa Exp $ */
+/* $Id: interface.c,v 1.62.2.14.2.51 2009/05/26 15:50:44 jani Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -370,7 +370,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() */
@@ -1460,6 +1460,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;
@@ -2046,6 +2060,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);
@@ -2068,6 +2087,9 @@
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.5r2=1.44.2.2.2.6diff_format=u
Index: php-src/ext/curl/php_curl.h
diff -u php-src/ext/curl/php_curl.h:1.44.2.2.2.5 
php-src/ext/curl/php_curl.h:1.44.2.2.2.6
--- php-src/ext/curl/php_curl.h:1.44.2.2.2.5Wed Dec 31 11:17:36 2008
+++ php-src/ext/curl/php_curl.h Tue May 26 15:50:44 2009
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: php_curl.h,v 1.44.2.2.2.5 2008/12/31 11:17:36 sebastian Exp $ */
+/* $Id: php_curl.h,v 1.44.2.2.2.6 2009/05/26 15:50:44 jani Exp $ */
 
 #ifndef _PHP_CURL_H
 #define _PHP_CURL_H
@@ -101,6 +101,7 @@
php_curl_write *write_header;
php_curl_read  *read;
  

Re: [PHP-CVS] cvs: php-src(PHP_5_2) / NEWS /ext/curl interface.c php_curl.h

2009-05-26 Thread Ilia Alshanetsky

On 26-May-09, at 11:50 AM, Jani Taskinen wrote:


janiTue May 26 15:50:44 2009 UTC

 Modified files:  (Branch: PHP_5_2)
   /php-src NEWS
   /php-src/ext/curlinterface.c php_curl.h
 Log:
 MFH:- Fixed bug #48203 (Crash when CURLOPT_STDERR is set to regular  
file)


Good stuff.


Ilia Alshanetsky


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



[PHP-CVS] cvs: php-src(PHP_5_2) / NEWS /ext/curl interface.c php_curl.h

2008-12-17 Thread Jani Taskinen
janiWed Dec 17 14:20:31 2008 UTC

  Modified files:  (Branch: PHP_5_2)
/php-srcNEWS 
/php-src/ext/curl   interface.c php_curl.h 
  Log:
  MFH:- Fixed bug #45161 (Reusing a curl handle leaks memory)
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1361r2=1.2027.2.547.2.1362diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1361 php-src/NEWS:1.2027.2.547.2.1362
--- php-src/NEWS:1.2027.2.547.2.1361Sat Dec 13 13:37:58 2008
+++ php-src/NEWSWed Dec 17 14:20:30 2008
@@ -13,6 +13,7 @@
 - Fixed bug #46739 (array returned by curl_getinfo should contain content_type 
key). 
   (Mikko)
 - Fixed bug #46699 (xml_parse crash when parser is namespace aware). (Rob)
+- Fixed bug #45161 (Reusing a curl handle leaks memory). (Mark Karpeles, Jani)
 - Fixed bug #35975 (Session cookie expires date format isn't the most 
compatible.
   Now matches that of setcookie()). (Scott)
 
http://cvs.php.net/viewvc.cgi/php-src/ext/curl/interface.c?r1=1.62.2.14.2.38r2=1.62.2.14.2.39diff_format=u
Index: php-src/ext/curl/interface.c
diff -u php-src/ext/curl/interface.c:1.62.2.14.2.38 
php-src/ext/curl/interface.c:1.62.2.14.2.39
--- php-src/ext/curl/interface.c:1.62.2.14.2.38 Thu Dec  4 13:13:41 2008
+++ php-src/ext/curl/interface.cWed Dec 17 14:20:30 2008
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: interface.c,v 1.62.2.14.2.38 2008/12/04 13:13:41 mkoppanen Exp $ */
+/* $Id: interface.c,v 1.62.2.14.2.39 2008/12/17 14:20:30 jani Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -996,6 +996,7 @@
 /* }}} */
 #endif
 
+#if LIBCURL_VERSION_NUM  0x071101
 /* {{{ curl_free_string
  */
 static void curl_free_string(void **string)
@@ -1003,6 +1004,7 @@
efree(*string);
 }  
 /* }}} */
+#endif
 
 /* {{{ curl_free_post
  */
@@ -1077,7 +1079,9 @@

memset((*ch)-err, 0, sizeof((*ch)-err));

+#if LIBCURL_VERSION_NUM  0x071101
zend_llist_init((*ch)-to_free.str,   sizeof(char *),
(llist_dtor_func_t) curl_free_string, 0);
+#endif
zend_llist_init((*ch)-to_free.slist, sizeof(struct curl_slist), 
(llist_dtor_func_t) curl_free_slist,  0);
zend_llist_init((*ch)-to_free.post,  sizeof(struct HttpPost),   
(llist_dtor_func_t) curl_free_post,   0);
 }
@@ -1136,11 +1140,15 @@
 #endif
 
if (argc  0) {
+#if LIBCURL_VERSION_NUM = 0x071100
+   curl_easy_setopt(ch-cp, CURLOPT_URL, Z_STRVAL_PP(url));
+#else
char *urlcopy;
 
urlcopy = estrndup(Z_STRVAL_PP(url), Z_STRLEN_PP(url));
curl_easy_setopt(ch-cp, CURLOPT_URL, urlcopy);
zend_llist_add_element(ch-to_free.str, urlcopy);
+#endif
}
 
ZEND_REGISTER_RESOURCE(return_value, ch, le_curl);
@@ -1206,9 +1214,11 @@
curl_easy_setopt(dupch-cp, CURLOPT_INFILE,(void *) dupch);
curl_easy_setopt(dupch-cp, CURLOPT_WRITEHEADER,   (void *) dupch);
 
+#if LIBCURL_VERSION_NUM  0x071101
zend_llist_copy(dupch-to_free.str, ch-to_free.str);
/* Don't try to free copied strings, they're free'd when the original 
handle is destroyed */
dupch-to_free.str.dtor = NULL;
+#endif
zend_llist_copy(dupch-to_free.slist, ch-to_free.slist);
zend_llist_copy(dupch-to_free.post, ch-to_free.post);
 
@@ -1331,7 +1341,9 @@
case CURLOPT_SSLENGINE_DEFAULT:
case CURLOPT_SSLCERTTYPE:
case CURLOPT_ENCODING: {
+#if LIBCURL_VERSION_NUM  0x071100
char *copystr = NULL;
+#endif

convert_to_string_ex(zvalue);
 
@@ -1339,9 +1351,14 @@

PHP_CURL_CHECK_OPEN_BASEDIR(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue), 1);
}
 
+#if LIBCURL_VERSION_NUM = 0x071100
+   /* Strings passed to libcurl as ’char *’ arguments, 
are copied by the library... NOTE: before 7.17.0 strings were not copied. */
+   error = curl_easy_setopt(ch-cp, option, 
Z_STRVAL_PP(zvalue));
+#else
copystr = estrndup(Z_STRVAL_PP(zvalue), 
Z_STRLEN_PP(zvalue));
error = curl_easy_setopt(ch-cp, option, copystr);
zend_llist_add_element(ch-to_free.str, copystr);
+#endif
 
break;
}
@@ -1532,6 +1549,11 @@
error = curl_easy_setopt(ch-cp, 
CURLOPT_HTTPPOST, first);
 
} else {
+#if LIBCURL_VERSION_NUM = 0x071101
+   /* with curl 7.17.0 and later, we can use 
COPYPOSTFIELDS, but we have to provide size before */
+   error = curl_easy_setopt(ch-cp, 
CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue));
+   error = curl_easy_setopt(ch-cp, 
CURLOPT_COPYPOSTFIELDS, Z_STRVAL_PP(zvalue));
+#else