fix env request
authorMichael Wallner <mike@php.net>
Wed, 21 Jan 2015 23:05:49 +0000 (00:05 +0100)
committerMichael Wallner <mike@php.net>
Wed, 21 Jan 2015 23:05:49 +0000 (00:05 +0100)
php_http_env.c
php_http_env_request.c

index 1e34fd10674d455e62317248d224cb8376e7a7a9..eef0c37aad541fb1d64ce933d13fd63a3ff2f19c 100644 (file)
@@ -952,13 +952,22 @@ static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
 
        if (json) {
                if (json->len) {
-                       zval zjson;
+                       zval tmp;
 
-                       ZVAL_NULL(&zjson);
-                       php_json_decode(&zjson, json->val, json->len, 1, PG(max_input_nesting_level));
-                       if (Z_TYPE(zjson) != IS_NULL) {
-                               zval_dtor(zarg);
-                               ZVAL_COPY_VALUE(zarg, (&zjson));
+                       ZVAL_NULL(&tmp);
+                       php_json_decode(&tmp, json->val, json->len, 1, PG(max_input_nesting_level));
+
+                       switch (Z_TYPE(tmp)) {
+                       case IS_NULL:
+                               break;
+
+                       case IS_ARRAY:
+                               array_copy(Z_ARRVAL(tmp), Z_ARRVAL_P(zarg));
+                               zval_ptr_dtor(&tmp);
+                               break;
+
+                       default:
+                               ZVAL_COPY_VALUE(zarg, &tmp);
                        }
                }
                zend_string_release(json);
index 6e2af5379c9ce415583dc561444484f1bf3ba58d..b1219665672bd8cfc8da68a73a309b6a70ea3550 100644 (file)
@@ -33,15 +33,15 @@ static int grab_file(zval *tmp_name, int argc, va_list argv, zend_hash_key *key)
 
                array_init(&entry);
 
-               Z_ADDREF_P(tmp_name);
+               Z_TRY_ADDREF_P(tmp_name);
                add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp_name);
-               Z_ADDREF_P(zname);
+               Z_TRY_ADDREF_P(zname);
                add_assoc_zval_ex(&entry, ZEND_STRL("name"), zname);
-               Z_ADDREF_P(zsize);
+               Z_TRY_ADDREF_P(zsize);
                add_assoc_zval_ex(&entry, ZEND_STRL("size"), zsize);
-               Z_ADDREF_P(ztype);
+               Z_TRY_ADDREF_P(ztype);
                add_assoc_zval_ex(&entry, ZEND_STRL("type"), ztype);
-               Z_ADDREF_P(zerror);
+               Z_TRY_ADDREF_P(zerror);
                add_assoc_zval_ex(&entry, ZEND_STRL("error"), zerror);
 
                if (file_key->key && (array = zend_hash_find(Z_ARRVAL_P(zfiles), file_key->key))) {
@@ -64,7 +64,7 @@ static int grab_file(zval *tmp_name, int argc, va_list argv, zend_hash_key *key)
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static int grab_files(zval *val TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int grab_files(zval *val, int argc, va_list argv, zend_hash_key *key)
 {
        zval *zfiles, *name, *tmp_name, *error, *type, *size;
 
@@ -91,18 +91,18 @@ static int grab_files(zval *val TSRMLS_DC, int argc, va_list argv, zend_hash_key
                                return ZEND_HASH_APPLY_STOP;
                        }
                } else  {
-                       zval *tmp;
+                       zval *tmp, entry;
 
-                       SEPARATE_ZVAL(val);
+                       ZVAL_DUP(&entry, val);
                        if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))) {
                                Z_ADDREF_P(tmp);
-                               add_assoc_zval_ex(val, ZEND_STRL("file"), tmp);
-                               zend_hash_str_del(Z_ARRVAL_P(val), ZEND_STRL("tmp_name"));
+                               add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp);
+                               zend_hash_str_del(Z_ARRVAL(entry), ZEND_STRL("tmp_name"));
                        }
                        if (key->key) {
-                               zend_hash_update(Z_ARRVAL_P(zfiles), key->key, val);
+                               zend_hash_update(Z_ARRVAL_P(zfiles), key->key, &entry);
                        } else {
-                               zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, val);
+                               zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, &entry);
                        }
                }
        }