Merge branch 'v3.1.x'
authorMichael Wallner <mike@php.net>
Mon, 3 Jul 2017 07:59:08 +0000 (09:59 +0200)
committerMichael Wallner <mike@php.net>
Mon, 3 Jul 2017 07:59:08 +0000 (09:59 +0200)
src/php_http_client.c
src/php_http_cookie.c
src/php_http_header.c
src/php_http_message.c
src/php_http_negotiate.h
src/php_http_params.c

index 7f8363ee4a69453f25d54a652813bc0f47fd619f..cedc239b68c1f780c2df5ef7b46b5bf74f448992 100644 (file)
@@ -75,6 +75,7 @@ void php_http_client_options_set_subr(zval *instance, char *key, size_t len, zva
 
                array_init(&new_opts);
                old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp);
+
                if (Z_TYPE_P(old_opts) == IS_ARRAY) {
                        array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL(new_opts));
                }
@@ -88,6 +89,7 @@ void php_http_client_options_set_subr(zval *instance, char *key, size_t len, zva
                        }
                } else if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
                        if ((entry = zend_symtable_str_find(Z_ARRVAL(new_opts), key, len))) {
+                               SEPARATE_ZVAL(entry);
                                array_join(Z_ARRVAL_P(opts), Z_ARRVAL_P(entry), 0, 0);
                        } else {
                                Z_ADDREF_P(opts);
index 2e2943338565c158cc86e0c1771ca09b991e063f..1186ca0535aa37394e90da8b9742e3a6d09d1bb7 100644 (file)
@@ -440,7 +440,7 @@ static PHP_METHOD(HttpCookie, __construct)
        HashTable *allowed_extras = NULL;
        zend_error_handling zeh;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!lH", &zcookie, &flags, &allowed_extras), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!lH/", &zcookie, &flags, &allowed_extras), invalid_arg, return);
 
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
@@ -526,7 +526,7 @@ static PHP_METHOD(HttpCookie, setCookies)
        HashTable *cookies = NULL;
        php_http_cookie_object_t *obj;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &cookies), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H/", &cookies), invalid_arg, return);
 
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
@@ -548,7 +548,7 @@ static PHP_METHOD(HttpCookie, addCookies)
        HashTable *cookies = NULL;
        php_http_cookie_object_t *obj;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H", &cookies), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H/", &cookies), invalid_arg, return);
 
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
@@ -585,7 +585,7 @@ static PHP_METHOD(HttpCookie, setExtras)
        HashTable *extras = NULL;
        php_http_cookie_object_t *obj;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &extras), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H/", &extras), invalid_arg, return);
 
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
@@ -607,7 +607,7 @@ static PHP_METHOD(HttpCookie, addExtras)
        HashTable *extras = NULL;
        php_http_cookie_object_t *obj;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H", &extras), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H/", &extras), invalid_arg, return);
 
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
index 91204c13fa7169f1ab25de7c9dc8dbbea6840e16..8c71cdeceaae7f2c4d75db7abe998477b24b4490 100644 (file)
@@ -100,6 +100,7 @@ void php_http_header_to_callback_ex(const char *key, zval *val, zend_bool crlf,
        zval *aval;
        zend_string *str;
 
+       ZVAL_DEREF(val);
        switch (Z_TYPE_P(val)) {
        case IS_ARRAY:
                ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(val), aval)
index feef2655f565357a9dbb74543da43cdb135755df..3f08ee46f681bb2860bb8c5ed8294bf005c2f415 100644 (file)
@@ -886,7 +886,7 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t
                        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
                        handler->read(obj, tmp);
 
-                       zval_ptr_dtor(return_value);
+                       //zval_ptr_dtor(return_value);
                        ZVAL_COPY_VALUE(return_value, tmp);
                }
                zend_string_release(member_name);
index 44f173589ea3369c54c87466fad1e7b9ac150472..07e556431831dd5630db88bfc0443becbcf566da 100644 (file)
@@ -74,9 +74,10 @@ static inline HashTable *php_http_negotiate_content_type(HashTable *supported, p
 #define PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported) \
        { \
                zval *value; \
+               HashPosition pos; \
                 \
-               zend_hash_internal_pointer_reset((supported)); \
-               if ((value = zend_hash_get_current_data((supported)))) { \
+               zend_hash_internal_pointer_reset_ex((supported), &pos); \
+               if ((value = zend_hash_get_current_data_ex((supported), &pos))) { \
                        RETVAL_ZVAL(value, 1, 0); \
                } else { \
                        RETVAL_NULL(); \
index 3ec71b1ddfd83f0d0b9465a26340dc6af903520c..9b40cfefdc767dafc1945213db20fdd45c17001a 100644 (file)
@@ -63,24 +63,26 @@ static inline void sanitize_escaped(zval *zv)
        php_stripcslashes(Z_STR_P(zv));
 }
 
-static inline void quote_string(zend_string **zs, zend_bool force)
+static inline zend_string *quote_string(zend_string *zs, zend_bool force)
 {
-       int len = (*zs)->len;
+       size_t len = (zs)->len;
 
-       *zs = php_addcslashes(*zs, 1, ZEND_STRL("\0..\37\173\\\""));
+       zs = php_addcslashes(zs, 0, ZEND_STRL("\0..\37\173\\\""));
 
-       if (force || len != (*zs)->len || strpbrk((*zs)->val, "()<>@,;:\"[]?={} ")) {
-               int len = (*zs)->len + 2;
+       if (force || len != (zs)->len || strpbrk((zs)->val, "()<>@,;:\"[]?={} ")) {
+               int len = (zs)->len + 2;
 
-               *zs = zend_string_extend(*zs, len, 0);
+               zs = zend_string_extend(zs, len, 0);
 
-               memmove(&(*zs)->val[1], (*zs)->val, (*zs)->len);
-               (*zs)->val[0] = '"';
-               (*zs)->val[len-1] = '"';
-               (*zs)->val[len] = '\0';
+               memmove(&(zs)->val[1], (zs)->val, (zs)->len);
+               (zs)->val[0] = '"';
+               (zs)->val[len-1] = '"';
+               (zs)->val[len] = '\0';
 
-               zend_string_forget_hash_val(*zs);
+               zend_string_forget_hash_val(zs);
        }
+
+       return zs;
 }
 
 /*     if (Z_TYPE_P(zv) == IS_STRING) {
@@ -109,7 +111,10 @@ static inline void quote_string(zend_string **zs, zend_bool force)
 static inline void prepare_escaped(zval *zv)
 {
        if (Z_TYPE_P(zv) == IS_STRING) {
-               quote_string(&Z_STR_P(zv), 0);
+               zend_string *str = quote_string(Z_STR_P(zv), 0);
+
+               zval_dtor(zv);
+               ZVAL_STR(zv, str);
        } else {
                zval_dtor(zv);
                ZVAL_EMPTY_STRING(zv);
@@ -816,13 +821,14 @@ static inline void shift_rfc5988(php_http_buffer_t *buf, char *key_str, size_t k
 
 static inline void shift_rfc5988_val(php_http_buffer_t *buf, zval *zv, const char *vss, size_t vsl, unsigned flags)
 {
-       zend_string *zs = zval_get_string(zv);
-
-       quote_string(&zs, 1);
-       php_http_buffer_append(buf, vss, vsl);
-       php_http_buffer_append(buf, zs->val, zs->len);
+       zend_string *str, *zs = zval_get_string(zv);
 
+       str = quote_string(zs, 1);
        zend_string_release(zs);
+
+       php_http_buffer_append(buf, vss, vsl);
+       php_http_buffer_append(buf, str->val, str->len);
+       zend_string_release(str);
 }
 
 static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags)