diff options
| author | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
|---|---|---|
| committer | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
| commit | cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch) | |
| tree | 1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /ext/curl | |
| parent | 9ea47aab740772adf0c69d8c94b208a464e599ea (diff) | |
| download | php-upstream/5.2.9.dfsg.1.tar.gz | |
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'ext/curl')
| -rw-r--r-- | ext/curl/config.m4 | 4 | ||||
| -rw-r--r-- | ext/curl/interface.c | 81 | ||||
| -rw-r--r-- | ext/curl/multi.c | 4 | ||||
| -rw-r--r-- | ext/curl/php_curl.h | 6 | ||||
| -rw-r--r-- | ext/curl/streams.c | 4 | ||||
| -rw-r--r-- | ext/curl/tests/bug45161.phpt | 36 | ||||
| -rw-r--r-- | ext/curl/tests/bug46739.phpt | 13 |
7 files changed, 125 insertions, 23 deletions
diff --git a/ext/curl/config.m4 b/ext/curl/config.m4 index c7a0f77b7..d53422a5d 100644 --- a/ext/curl/config.m4 +++ b/ext/curl/config.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.28.2.3.2.7 2007/05/25 12:47:55 mike Exp $ +dnl $Id: config.m4,v 1.28.2.3.2.8 2008/11/07 21:18:45 felipe Exp $ dnl PHP_ARG_WITH(curl, for cURL support, @@ -75,7 +75,7 @@ if test "$PHP_CURL" != "no"; then } ],[ AC_MSG_RESULT([yes]) - AC_CHECK_HEADER([openssl/crypto.h], [ + AC_CHECK_HEADERS([openssl/crypto.h], [ AC_DEFINE([HAVE_CURL_OPENSSL], [1], [Have cURL with OpenSSL support]) ]) ], [ diff --git a/ext/curl/interface.c b/ext/curl/interface.c index ff702f20b..9c72e3927 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: interface.c,v 1.62.2.14.2.34 2008/01/06 17:12:29 iliaa Exp $ */ +/* $Id: interface.c,v 1.62.2.14.2.41 2009/01/26 15:25:23 iliaa Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS @@ -786,7 +786,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) { php_curl *ch = (php_curl *) ctx; php_curl_read *t = ch->handlers->read; - int length = -1; + int length = 0; switch (t->method) { case PHP_CURL_DIRECT: @@ -833,7 +833,9 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) ch->in_callback = 0; if (error == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_READFUNCTION"); - length = -1; +#if LIBCURL_VERSION_NUM >= 0x070c01 /* 7.12.1 */ + length = CURL_READFUNC_ABORT; +#endif } else if (retval_ptr) { if (Z_TYPE_P(retval_ptr) == IS_STRING) { length = MIN(size * nmemb, Z_STRLEN_P(retval_ptr)); @@ -994,6 +996,7 @@ static size_t curl_passwd(void *ctx, char *prompt, char *buf, int buflen) /* }}} */ #endif +#if LIBCURL_VERSION_NUM < 0x071101 /* {{{ curl_free_string */ static void curl_free_string(void **string) @@ -1001,6 +1004,7 @@ static void curl_free_string(void **string) efree(*string); } /* }}} */ +#endif /* {{{ curl_free_post */ @@ -1075,7 +1079,9 @@ static void alloc_curl_handle(php_curl **ch) 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); } @@ -1134,11 +1140,15 @@ PHP_FUNCTION(curl_init) #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); @@ -1204,9 +1214,11 @@ PHP_FUNCTION(curl_copy_handle) 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); @@ -1329,7 +1341,9 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu case CURLOPT_SSLENGINE_DEFAULT: case CURLOPT_SSLCERTTYPE: case CURLOPT_ENCODING: { +#if LIBCURL_VERSION_NUM < 0x071100 char *copystr = NULL; +#endif convert_to_string_ex(zvalue); @@ -1337,9 +1351,14 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu 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, ©str); +#endif break; } @@ -1419,7 +1438,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu case CURLOPT_READFUNCTION: if (ch->handlers->read->func_name) { zval_ptr_dtor(&ch->handlers->read->func_name); - ch->handlers->write->fci_cache = empty_fcall_info_cache; + ch->handlers->read->fci_cache = empty_fcall_info_cache; } zval_add_ref(zvalue); ch->handlers->read->func_name = *zvalue; @@ -1428,7 +1447,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu case CURLOPT_HEADERFUNCTION: if (ch->handlers->write_header->func_name) { zval_ptr_dtor(&ch->handlers->write_header->func_name); - ch->handlers->write->fci_cache = empty_fcall_info_cache; + ch->handlers->write_header->fci_cache = empty_fcall_info_cache; } zval_add_ref(zvalue); ch->handlers->write_header->func_name = *zvalue; @@ -1479,17 +1498,36 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu * must be explicitly cast to long in curl_formadd * use since curl needs a long not an int. */ if (*postval == '@') { + char *type; ++postval; + + if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + strlen(postval)))) { + *type = '\0'; + } /* safe_mode / open_basedir check */ if (php_check_open_basedir(postval TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(postval, "rb+", CHECKUID_CHECK_MODE_PARAM))) { + if (type) { + *type = ';'; + } RETVAL_FALSE; return 1; } - error = curl_formadd(&first, &last, + if (type) { + error = curl_formadd(&first, &last, CURLFORM_COPYNAME, string_key, CURLFORM_NAMELENGTH, (long)string_key_len - 1, - CURLFORM_FILE, postval, + CURLFORM_FILE, postval, + CURLFORM_CONTENTTYPE, type + sizeof(";type=") - 1, CURLFORM_END); + *type = ';'; + } else { + error = curl_formadd(&first, &last, + CURLFORM_COPYNAME, string_key, + CURLFORM_NAMELENGTH, (long)string_key_len - 1, + CURLFORM_FILE, postval, + CURLFORM_END); + + } } else { error = curl_formadd(&first, &last, CURLFORM_COPYNAME, string_key, @@ -1510,6 +1548,11 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu 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 char *post = NULL; convert_to_string_ex(zvalue); @@ -1518,6 +1561,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post); error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_PP(zvalue)); +#endif } break; case CURLOPT_HTTPHEADER: @@ -1539,20 +1583,15 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu zend_hash_get_current_data(ph, (void **) ¤t) == SUCCESS; zend_hash_move_forward(ph) ) { - char *indiv = NULL; - SEPARATE_ZVAL(current); convert_to_string_ex(current); - indiv = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current) + 1); - slist = curl_slist_append(slist, indiv); + slist = curl_slist_append(slist, Z_STRVAL_PP(current)); if (!slist) { - efree(indiv); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not build curl_slist"); RETVAL_FALSE; return 1; } - zend_llist_add_element(&ch->to_free.str, &indiv); } zend_llist_add_element(&ch->to_free.slist, &slist); @@ -1567,7 +1606,9 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu case CURLOPT_SSLCERT: case CURLOPT_RANDOM_FILE: case CURLOPT_COOKIEFILE: { +#if LIBCURL_VERSION_NUM < 0x071100 char *copystr = NULL; +#endif convert_to_string_ex(zvalue); @@ -1576,11 +1617,14 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu return 1; } +#if LIBCURL_VERSION_NUM >= 0x071100 + 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, ©str); - +#endif break; } case CURLINFO_HEADER_OUT: @@ -1748,6 +1792,11 @@ PHP_FUNCTION(curl_getinfo) if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) { if (s_code != NULL) { CAAS("content_type", s_code); + } else { + zval *retnull; + MAKE_STD_ZVAL(retnull); + ZVAL_NULL(retnull); + CAAZ("content_type", retnull); } } if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) { @@ -1941,7 +1990,9 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) #endif curl_easy_cleanup(ch->cp); +#if LIBCURL_VERSION_NUM < 0x071101 zend_llist_clean(&ch->to_free.str); +#endif zend_llist_clean(&ch->to_free.slist); zend_llist_clean(&ch->to_free.post); diff --git a/ext/curl/multi.c b/ext/curl/multi.c index cefc5f441..2e6580ace 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: multi.c,v 1.19.2.3.2.9 2007/12/31 07:20:05 sebastian Exp $ */ +/* $Id: multi.c,v 1.19.2.3.2.10 2008/12/31 11:17:36 sebastian Exp $ */ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index b17df0a77..f38e20026 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_curl.h,v 1.44.2.2.2.3 2007/12/31 07:20:05 sebastian Exp $ */ +/* $Id: php_curl.h,v 1.44.2.2.2.5 2008/12/31 11:17:36 sebastian Exp $ */ #ifndef _PHP_CURL_H #define _PHP_CURL_H @@ -114,7 +114,9 @@ struct _php_curl_send_headers { }; struct _php_curl_free { +#if LIBCURL_VERSION_NUM < 0x071100 zend_llist str; +#endif zend_llist post; zend_llist slist; }; diff --git a/ext/curl/streams.c b/ext/curl/streams.c index 2d73f25c8..c2a9a5d57 100644 --- a/ext/curl/streams.c +++ b/ext/curl/streams.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2008 The PHP Group | + | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.14.2.2.2.12 2007/12/31 07:20:05 sebastian Exp $ */ +/* $Id: streams.c,v 1.14.2.2.2.13 2008/12/31 11:17:36 sebastian Exp $ */ /* This file implements cURL based wrappers. * NOTE: If you are implementing your own streams that are intended to diff --git a/ext/curl/tests/bug45161.phpt b/ext/curl/tests/bug45161.phpt new file mode 100644 index 000000000..eab1fd46e --- /dev/null +++ b/ext/curl/tests/bug45161.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #45161 (Reusing a curl handle leaks memory) +--FILE-- +<?php + +// Fill memory for test +$ch = curl_init(); +$fp = fopen('/dev/null', 'w'); + +/* +$i = $start = $end = 100000.00; +for ($i = 0; $i < 100; $i++) { + curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:9/'); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_exec($ch); +} +*/ + +// Start actual test +$start = memory_get_usage() + 1024; +for($i = 0; $i < 1024; $i++) { + curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:9/'); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_exec($ch); +} +if ($start < memory_get_usage()) { + echo 'FAIL'; +} else { + echo 'PASS'; +} +echo "\n"; +fclose($fp); +unset($fp); +?> +--EXPECT-- +PASS diff --git a/ext/curl/tests/bug46739.phpt b/ext/curl/tests/bug46739.phpt new file mode 100644 index 000000000..06a84ea8e --- /dev/null +++ b/ext/curl/tests/bug46739.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #46739 (array returned by curl_getinfo should contain content_type key) +--FILE-- +<?php +$ch = curl_init('http://127.0.0.1:9/'); + +curl_exec($ch); +$info = curl_getinfo($ch); + +echo (array_key_exists('content_type', $info)) ? "set" : "not set"; +?> +--EXPECT-- +set |
