com php-src: Fixed bug #69970 (Use-after-free vulnerability in spl_recursive_it_move_forward_ex()): ext/sp l/spl_iterators.c
ext/spl/tests/bug69970.phpt
| From: | Ferenc Kovacs | Date: | Fri, 10 Jul 2015 00:27:09 +0000 |
| Subject: | com php-src: Fixed bug #69970 (Use-after-free vulnerability in spl_recursive_it_move_forward_ex()): ext/sp l/spl_iterators.c ext/spl/tests/bug69970.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87890@lists.php.net to get a copy of this message | ||
Commit: 1f4a84109549480a40b3c3b49456aa7bb4105bac
Author: Xinchen Hui <laruence@php.net> Tue, 7 Jul 2015 21:25:28 +0800
Committer: Ferenc Kovacs <tyrael@php.net> Fri, 10 Jul 2015 02:27:09 +0200
Parents: d1370e201609b0a9010a83bed9071c2a39741612
Branches: PHP-5.6.11
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1f4a84109549480a40b3c3b49456aa7bb4105bac
Log:
Fixed bug #69970 (Use-after-free vulnerability in spl_recursive_it_move_forward_ex())
Bugs:
https://bugs.php.net/69970
Changed paths:
M ext/spl/spl_iterators.c
A ext/spl/tests/bug69970.phpt
Diff:
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 8588c7a..359d94d 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -380,9 +380,11 @@ next_step:
}
}
}
- iterator->funcs->dtor(iterator TSRMLS_CC);
- zval_ptr_dtor(&object->iterators[object->level].zobject);
- object->level--;
+ if (object->level > 0) {
+ iterator->funcs->dtor(iterator TSRMLS_CC);
+ zval_ptr_dtor(&object->iterators[object->level].zobject);
+ object->level--;
+ }
} else {
return; /* done completeley */
}
diff --git a/ext/spl/tests/bug69970.phpt b/ext/spl/tests/bug69970.phpt
new file mode 100644
index 0000000..a488037
--- /dev/null
+++ b/ext/spl/tests/bug69970..phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #69970 (Use-after-free vulnerability in spl_recursive_it_move_forward_ex())
+--FILE--
+<?php
+
+$count = 10;
+
+class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator {
+ function rewind() {
+ echo "dummy\n";
+ }
+ function endChildren() {
+ global $count;
+ echo $this->getDepth();
+ if (--$count > 0) {
+ // Trigger use-after-free
+ parent::rewind();
+ }
+ }
+}
+$arr = array("a", array("ba", array("bba", "bbb")));
+$obj = new RecursiveArrayIterator($arr);
+$rit = new RecursiveArrayIteratorIterator($obj);
+
+foreach ($rit as $k => $v) {
+ echo ($rit->getDepth()) . "$k=>$v\n";
+}
+?>
+--EXPECT--
+dummy
+00=>a
+00=>a
+10=>ba
+20=>bba
+21=>bbb
+21010=>ba
+20=>bba
+21=>bbb
+21010=>ba
+20=>bba
+21=>bbb
+21010=>ba
+20=>bba
+21=>bbb
+21