iliaa Tue, 30 Nov 2010 13:40:02 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305850
Log: Fixed bug #52202 (CURLOPT_PRIVATE gets corrupted). Bug: http://bugs.php.net/52202 (Open) CURL(OPT|INFO)_PRIVATE Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/curl/interface.c A php/php-src/branches/PHP_5_3/ext/curl/tests/bug52202.phpt U php/php-src/trunk/ext/curl/interface.c A php/php-src/trunk/ext/curl/tests/bug52202.phpt Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-11-30 12:51:57 UTC (rev 305849) +++ php/php-src/branches/PHP_5_3/NEWS 2010-11-30 13:40:02 UTC (rev 305850) @@ -17,6 +17,7 @@ - Curl extension: . Fixed bug #52828 (curl_setopt does not accept persistent streams). (Gustavo, Ilia) + . Fixed bug #52202 (CURLOPT_PRIVATE gets corrupted). (Ilia) - DOM extension: . Fixed bug #52656 (DOMCdataSection does not work with splitText). (Ilia) Modified: php/php-src/branches/PHP_5_3/ext/curl/interface.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/curl/interface.c 2010-11-30 12:51:57 UTC (rev 305849) +++ php/php-src/branches/PHP_5_3/ext/curl/interface.c 2010-11-30 13:40:02 UTC (rev 305850) @@ -1252,7 +1252,6 @@ /* }}} */ #endif -#if LIBCURL_VERSION_NUM < 0x071101 /* {{{ curl_free_string */ static void curl_free_string(void **string) @@ -1260,7 +1259,6 @@ efree(*string); } /* }}} */ -#endif /* {{{ curl_free_post */ @@ -1337,9 +1335,7 @@ 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); } @@ -1556,11 +1552,10 @@ 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); @@ -1742,14 +1737,22 @@ return 1; } } else { + if (option == CURLOPT_PRIVATE) { + char *copystr; +#if LIBCURL_VERSION_NUM < 0x071100 +string_copy: +#endif + 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); + } else { #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); + /* 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 + goto string_copy; #endif + } } break; } @@ -2456,9 +2459,7 @@ } curl_easy_cleanup(ch->cp); -#if LIBCURL_VERSION_NUM < 0x071101 zend_llist_clean(&ch->to_free.str); -#endif /* cURL destructors should be invoked only by last curl handle */ if (Z_REFCOUNT_P(ch->clone) <= 1) { Added: php/php-src/branches/PHP_5_3/ext/curl/tests/bug52202.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/curl/tests/bug52202.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/curl/tests/bug52202.phpt 2010-11-30 13:40:02 UTC (rev 305850) @@ -0,0 +1,16 @@ +--TEST-- +Bug #52202 (CURLOPT_PRIVATE gets clobbered) +--SKIPIF-- +<?php +if (!extension_loaded('curl')) exit("skip curl extension not loaded"); +?> +--FILE-- +<?php +$curl = curl_init("http://www.google.com"); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($curl, CURLOPT_PRIVATE, "123"); +curl_exec($curl); + +var_dump(curl_getinfo($curl, CURLINFO_PRIVATE)); +--EXPECT-- +string(3) "123" Modified: php/php-src/trunk/ext/curl/interface.c =================================================================== --- php/php-src/trunk/ext/curl/interface.c 2010-11-30 12:51:57 UTC (rev 305849) +++ php/php-src/trunk/ext/curl/interface.c 2010-11-30 13:40:02 UTC (rev 305850) @@ -1255,7 +1255,6 @@ /* }}} */ #endif -#if LIBCURL_VERSION_NUM < 0x071101 /* {{{ curl_free_string */ static void curl_free_string(void **string) @@ -1263,7 +1262,6 @@ efree(*string); } /* }}} */ -#endif /* {{{ curl_free_post */ @@ -1340,9 +1338,7 @@ 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); } @@ -1559,11 +1555,10 @@ 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); @@ -1752,14 +1747,22 @@ return 1; } } else { + if (option == CURLOPT_PRIVATE) { + char *copystr; +#if LIBCURL_VERSION_NUM < 0x071100 +string_copy: +#endif + 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); + } else { #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); + /* 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 + goto string_copy; #endif + } } break; } @@ -2466,9 +2469,7 @@ } curl_easy_cleanup(ch->cp); -#if LIBCURL_VERSION_NUM < 0x071101 zend_llist_clean(&ch->to_free.str); -#endif /* cURL destructors should be invoked only by last curl handle */ if (Z_REFCOUNT_P(ch->clone) <= 1) { Added: php/php-src/trunk/ext/curl/tests/bug52202.phpt =================================================================== --- php/php-src/trunk/ext/curl/tests/bug52202.phpt (rev 0) +++ php/php-src/trunk/ext/curl/tests/bug52202.phpt 2010-11-30 13:40:02 UTC (rev 305850) @@ -0,0 +1,16 @@ +--TEST-- +Bug #52202 (CURLOPT_PRIVATE gets clobbered) +--SKIPIF-- +<?php +if (!extension_loaded('curl')) exit("skip curl extension not loaded"); +?> +--FILE-- +<?php +$curl = curl_init("http://www.google.com"); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($curl, CURLOPT_PRIVATE, "123"); +curl_exec($curl); + +var_dump(curl_getinfo($curl, CURLINFO_PRIVATE)); +--EXPECT-- +string(3) "123"
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php