diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-12 10:37:17 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-12 10:37:17 +0200 |
commit | 1ef5b79b6be380c133b21fd17b39a9aef4cccae6 (patch) | |
tree | 3e4582f3c376cf88df1cf3559a23c86511159b71 | |
parent | 8e8d129d7f2104ec0e1634e11126bfdfd5fb15e1 (diff) | |
parent | 354a1c27aad72b77d91bc130716c0c3bd4617463 (diff) | |
download | php-git-1ef5b79b6be380c133b21fd17b39a9aef4cccae6.tar.gz |
Merge branch 'PHP-7.3' into PHP-7.4
-rw-r--r-- | ext/mbstring/mbstring.c | 10 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_convert_encoding_leak.phpt | 16 |
2 files changed, 22 insertions, 4 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 08ac6b9a29..ca57b7eb15 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -3249,7 +3249,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons { HashTable *output, *chash; zend_long idx; - zend_string *key, *key_tmp; + zend_string *key; zval *entry, entry_tmp; size_t ckey_len, cval_len; char *ckey, *cval; @@ -3269,7 +3269,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons /* convert key */ if (key) { ckey = php_mb_convert_encoding(ZSTR_VAL(key), ZSTR_LEN(key), _to_encoding, _from_encodings, &ckey_len); - key_tmp = zend_string_init(ckey, ckey_len, 0); + key = zend_string_init(ckey, ckey_len, 0); + efree(ckey); } /* convert value */ ZEND_ASSERT(entry); @@ -3297,13 +3298,14 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons case IS_OBJECT: default: if (key) { - efree(key_tmp); + zend_string_release(key); } php_error_docref(NULL, E_WARNING, "Object is not supported"); continue; } if (key) { - zend_hash_add(output, key_tmp, &entry_tmp); + zend_hash_add(output, key, &entry_tmp); + zend_string_release(key); } else { zend_hash_index_add(output, idx, &entry_tmp); } diff --git a/ext/mbstring/tests/mb_convert_encoding_leak.phpt b/ext/mbstring/tests/mb_convert_encoding_leak.phpt new file mode 100644 index 0000000000..4e626b0894 --- /dev/null +++ b/ext/mbstring/tests/mb_convert_encoding_leak.phpt @@ -0,0 +1,16 @@ +--TEST-- +mb_convert_encoding() shouldn't leak keys +--FILE-- +<?php + +$x = "x"; +$array = ["foo" . $x => "bar"]; +mb_convert_encoding($array, 'UTF-8', 'UTF-8'); +var_dump($array); + +?> +--EXPECT-- +array(1) { + ["foox"]=> + string(3) "bar" +} |