com php-src: Fixed bug #67539 (ArrayIterator use-after-free due to object change during sorting): ext/spl/spl_array.c ext/spl/tests /bug67539.phpt
| From: | Stanislav Malyshev | Date: | Fri, 25 Jul 2014 05:54:14 +0000 |
| Subject: | com php-src: Fixed bug #67539 (ArrayIterator use-after-free due to object change during sorting): ext/spl/spl_array.c ext/spl/tests /bug67539.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79589@lists.php.net to get a copy of this message | ||
Commit: 51c38a09970c1f8395e68500c0b2ed1b3c9a6786
Author: Xinchen Hui <laruence@php.net> Wed, 2 Jul 2014 17:57:42 +0800
Committer: Stanislav Malyshev <stas@php.net> Thu, 24 Jul 2014 22:54:14 -0700
Parents: 61e0f8599d4e2a222ec49781e5be90fbbc1cd65b
Branches: PHP-5.4 PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=51c38a09970c1f8395e68500c0b2ed1b3c9a6786
Log:
Fixed bug #67539 (ArrayIterator use-after-free due to object change during sorting)
Bugs:
https://bugs.php.net/67539
Changed paths:
M ext/spl/spl_array.c
A ext/spl/tests/bug67539.phpt
Diff:
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index bf034ab..ec9ce21 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -1745,6 +1745,7 @@ SPL_METHOD(Array, unserialize)
const unsigned char *p, *s;
php_unserialize_data_t var_hash;
zval *pmembers, *pflags = NULL;
+ HashTable *aht;
long flags;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) ==
FAILURE) {
@@ -1756,6 +1757,12 @@ SPL_METHOD(Array, unserialize)
return;
}
+ aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
+ if (aht->nApplyCount > 0) {
+ zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+ return;
+ }
+
/* storage */
s = p = (const unsigned char*)buf;
PHP_VAR_UNSERIALIZE_INIT(var_hash);
diff --git a/ext/spl/tests/bug67539.phpt b/ext/spl/tests/bug67539.phpt
new file mode 100644
index 0000000..8bab2a8
--- /dev/null
+++ b/ext/spl/tests/bug67539.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #67539 (ArrayIterator use-after-free due to object change during sorting)
+--FILE--
+<?php
+
+$it = new ArrayIterator(array_fill(0,2,'X'), 1 );
+
+function badsort($a, $b) {
+ $GLOBALS['it']->unserialize($GLOBALS['it']->serialize());
+ return TRUE;
+}
+
+$it->uksort('badsort');
+--EXPECTF--
+Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d