~hexmode/ubuntu/lucid/php5/php5.fix-php-bug-33210

« back to all changes in this revision

Viewing changes to ext/curl/interface.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 01:44:25 UTC
  • mfrom: (1.1.15 upstream) (0.3.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106014425-5dsqjhbg303h3kfn
Tags: 5.2.11.dfsg.1-1ubuntu1
* Merge from debian testing, remaining changes:
  - debian/control, debian/rules: Disable a few build dependencies and
    accompanying, binary packages which we do not want to support in main:
    + firebird2-dev/php5-interbase (we have a seperate php-interbase source)
    + libc-client/php5-imap (we have a seperate php-imap source)
    + libmcrypt-dev/php5-mcrypt (seperate php-mycrpt source)
    + readline support again, now that the libedit issue is fixed.
  - debian/control: Add build dependency: libdedit-dev (>= 2.9.cvs.20050518-1)
    CLI readline support.
  - debian/rules:
    + Correctly mangle PHP5_* macros for lpia
  - debian/control:
    + Use libdb-4.6-dev.
    + Rename Vcs-Browser & Vcs-Git to XS-Original-Vcs-Browser & XS-Original-Vcs-Git (LP: #323731).
  - Dropped patches:
    - debian/patches/119-sybase-alias.patch: Use Debian's patch.
    - debian/patches/fix-autoconf-ftbfs.patch: Use Debian's patch
    - debian/patches/fix-zlib-decompression: Already in upstream
  - Use the default pear/install-pear-nozlib.phar in php 5.2.11
  - debian/control: Move php5-suhoshin to Suggests.
  - debian/rules: Fix broken symlink for pear.
  - Dropped dependency on autoconf2.13.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
   +----------------------------------------------------------------------+
17
17
*/
18
18
 
19
 
/* $Id: interface.c,v 1.62.2.14.2.57 2009/06/15 12:38:11 iliaa Exp $ */
 
19
/* $Id: interface.c 287784 2009-08-26 22:24:10Z pajoye $ */
20
20
 
21
21
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
22
22
 
183
183
                        return 0;
184
184
                }
185
185
 
186
 
                if (!strncasecmp("file", uri->scheme, sizeof("file"))) {
 
186
                if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) {
187
187
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol 'file' disabled in cURL");
188
188
                        php_url_free(uri);
189
189
                        return 0;
696
696
                char **p = (char **)info->protocols;
697
697
 
698
698
                while (*p != NULL) {
699
 
                        php_register_url_stream_wrapper(*p++, &php_curl_wrapper TSRMLS_CC);
 
699
                        /* Do not enable cURL "file" protocol and make sure cURL is always used when --with-curlwrappers is enabled */
 
700
                        if (strncasecmp(*p, "file", sizeof("file")-1) != 0) {
 
701
                                php_unregister_url_stream_wrapper(*p TSRMLS_CC);
 
702
                                php_register_url_stream_wrapper(*p, &php_curl_wrapper TSRMLS_CC);
 
703
                        }
 
704
                        (void) *p++;
700
705
                }
701
706
        }
702
707
# else
 
708
        php_unregister_url_stream_wrapper("http");
703
709
        php_register_url_stream_wrapper("http", &php_curl_wrapper TSRMLS_CC);
 
710
        php_unregister_url_stream_wrapper("https");
704
711
        php_register_url_stream_wrapper("https", &php_curl_wrapper TSRMLS_CC);
 
712
        php_unregister_url_stream_wrapper("ftp");
705
713
        php_register_url_stream_wrapper("ftp", &php_curl_wrapper TSRMLS_CC);
 
714
        php_unregister_url_stream_wrapper("ftps");
 
715
        php_register_url_stream_wrapper("ftps", &php_curl_wrapper TSRMLS_CC);
 
716
        php_unregister_url_stream_wrapper("ldap");
706
717
        php_register_url_stream_wrapper("ldap", &php_curl_wrapper TSRMLS_CC);
707
718
# endif
708
719
#endif
1131
1142
{
1132
1143
        php_curl        *ch;
1133
1144
        zval            **url;
 
1145
        zval            *clone;
1134
1146
        CURL            *cp;
1135
1147
        int                     argc = ZEND_NUM_ARGS();
1136
1148
 
1160
1172
 
1161
1173
        ch->uses = 0;
1162
1174
 
 
1175
        MAKE_STD_ZVAL(clone);
 
1176
        ch->clone = clone;
 
1177
 
1163
1178
        curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS,        1);
1164
1179
        curl_easy_setopt(ch->cp, CURLOPT_VERBOSE,           0);
1165
1180
        curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER,       ch->err.str);
1255
1270
        zend_llist_copy(&dupch->to_free.slist, &ch->to_free.slist);
1256
1271
        zend_llist_copy(&dupch->to_free.post, &ch->to_free.post);
1257
1272
 
 
1273
        /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
 
1274
        ch->clone->refcount++;
 
1275
        dupch->clone = ch->clone;
 
1276
 
1258
1277
        ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl);
1259
1278
        dupch->id = Z_LVAL_P(return_value);
1260
1279
}
1436
1455
                        error = CURLE_OK;
1437
1456
                        switch (option) {
1438
1457
                                case CURLOPT_FILE:
1439
 
                                        if (((php_stream *) what)->mode[0] != 'r') {
 
1458
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1440
1459
                                                zend_list_addref(Z_LVAL_PP(zvalue));
1441
1460
                                                ch->handlers->write->fp = fp;
1442
1461
                                                ch->handlers->write->method = PHP_CURL_FILE;
1447
1466
                                        }
1448
1467
                                        break;
1449
1468
                                case CURLOPT_WRITEHEADER:
1450
 
                                        if (((php_stream *) what)->mode[0] != 'r') {
 
1469
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1451
1470
                                                zend_list_addref(Z_LVAL_PP(zvalue));
1452
1471
                                                ch->handlers->write_header->fp = fp;
1453
1472
                                                ch->handlers->write_header->method = PHP_CURL_FILE;
1463
1482
                                        ch->handlers->read->fd = Z_LVAL_PP(zvalue);
1464
1483
                                        break;
1465
1484
                                case CURLOPT_STDERR:
1466
 
                                        if (((php_stream *) what)->mode[0] != 'r') {
 
1485
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1467
1486
                                                if (ch->handlers->std_err) {
1468
1487
                                                        zval_ptr_dtor(&ch->handlers->std_err);
1469
1488
                                                }
1573
1592
                                         * must be explicitly cast to long in curl_formadd
1574
1593
                                         * use since curl needs a long not an int. */
1575
1594
                                        if (*postval == '@') {
1576
 
                                                char *type;
 
1595
                                                char *type, *filename;
1577
1596
                                                ++postval;
1578
1597
 
1579
 
                                                if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + strlen(postval)))) {
 
1598
                                                if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + Z_STRLEN_PP(current)))) {
1580
1599
                                                        *type = '\0';
1581
1600
                                                }
 
1601
                                                if ((filename = php_memnstr(postval, ";filename=", sizeof(";filename=") - 1, postval + Z_STRLEN_PP(current)))) {
 
1602
                                                        *filename = '\0';
 
1603
                                                }
1582
1604
                                                /* safe_mode / open_basedir check */
1583
1605
                                                if (php_check_open_basedir(postval TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(postval, "rb+", CHECKUID_CHECK_MODE_PARAM))) {
1584
 
                                                        if (type) {
1585
 
                                                                *type = ';';
1586
 
                                                        }
1587
1606
                                                        RETVAL_FALSE;
1588
1607
                                                        return 1;
1589
1608
                                                }
 
1609
                                                error = curl_formadd(&first, &last,
 
1610
                                                                                CURLFORM_COPYNAME, string_key,
 
1611
                                                                                CURLFORM_NAMELENGTH, (long)string_key_len - 1,
 
1612
                                                                                CURLFORM_FILENAME, filename ? filename : postval,
 
1613
                                                                                CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream",
 
1614
                                                                                CURLFORM_FILE, postval,
 
1615
                                                                                CURLFORM_END);
1590
1616
                                                if (type) {
1591
 
                                                        error = curl_formadd(&first, &last,
1592
 
                                                                                         CURLFORM_COPYNAME, string_key,
1593
 
                                                                                         CURLFORM_NAMELENGTH, (long)string_key_len - 1,
1594
 
                                                                                         CURLFORM_FILE, postval,
1595
 
                                                                                         CURLFORM_CONTENTTYPE, type + sizeof(";type=") - 1,
1596
 
                                                                                         CURLFORM_END);
1597
1617
                                                        *type = ';';
1598
 
                                                } else {
1599
 
                                                        error = curl_formadd(&first, &last,
1600
 
                                                                                         CURLFORM_COPYNAME, string_key,
1601
 
                                                                                         CURLFORM_NAMELENGTH, (long)string_key_len - 1,
1602
 
                                                                                         CURLFORM_FILE, postval,
1603
 
                                                                                         CURLFORM_END);
1604
 
 
 
1618
                                                }
 
1619
                                                if (filename) {
 
1620
                                                        *filename = ';';
1605
1621
                                                }
1606
1622
                                        } else {
1607
1623
                                                error = curl_formadd(&first, &last,
1829
1845
                RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1);
1830
1846
        }
1831
1847
 
 
1848
        /* flush the file handle, so any remaining data is synched to disk */
 
1849
        if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
 
1850
                fflush(ch->handlers->write->fp);
 
1851
        }
 
1852
        if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
 
1853
                fflush(ch->handlers->write_header->fp);
 
1854
        }
 
1855
 
1832
1856
        if (ch->handlers->write->method == PHP_CURL_RETURN) {
1833
1857
                RETURN_EMPTY_STRING();
1834
1858
        } else {
2068
2092
#if LIBCURL_VERSION_NUM < 0x071101
2069
2093
        zend_llist_clean(&ch->to_free.str);
2070
2094
#endif
2071
 
        zend_llist_clean(&ch->to_free.slist);
2072
 
        zend_llist_clean(&ch->to_free.post);
 
2095
 
 
2096
        /* cURL destructors should be invoked only by last curl handle */
 
2097
        if (ch->clone->refcount <= 1) {
 
2098
                zend_llist_clean(&ch->to_free.slist);
 
2099
                zend_llist_clean(&ch->to_free.post);
 
2100
                FREE_ZVAL(ch->clone);
 
2101
        } else {
 
2102
                ch->clone->refcount--;
 
2103
                ch->to_free.slist.dtor = NULL;
 
2104
                ch->to_free.post.dtor = NULL;
 
2105
                zend_llist_clean(&ch->to_free.slist);
 
2106
                zend_llist_clean(&ch->to_free.post);
 
2107
        }
2073
2108
 
2074
2109
        if (ch->handlers->write->buf.len > 0) {
2075
2110
                smart_str_free(&ch->handlers->write->buf);