From: Michael Wallner Date: Wed, 21 Jan 2015 23:05:49 +0000 (+0100) Subject: fix env request X-Git-Tag: RELEASE_3_0_0_RC1~74 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c51b7204d895c33124de9799fdbe16eb7bb8158d;p=m6w6%2Fext-http fix env request --- diff --git a/php_http_env.c b/php_http_env.c index 1e34fd1..eef0c37 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -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); diff --git a/php_http_env_request.c b/php_http_env_request.c index 6e2af53..b121966 100644 --- a/php_http_env_request.c +++ b/php_http_env_request.c @@ -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); } } }