summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-10-18 17:20:00 -0700
committerStanislav Malyshev <stas@php.net>2015-10-18 17:20:00 -0700
commit26e5429f721b40d6d721fa9e2e2ede5f6222798c (patch)
treea3ba41935f66ddadadd1cf6356a4a07521e81b97
parent307c1f6bf0e8e3c97416b2a22ed54dd4546ea689 (diff)
parent0b35e0c5a120c9ff98dad7e44259f26ca828a8e4 (diff)
downloadphp-git-26e5429f721b40d6d721fa9e2e2ede5f6222798c.tar.gz
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6: Fix bug #64172 Bug #70561: Fix DirectoryIterator to throw OutOfBoundsException Conflicts: ext/pdo/pdo_dbh.c
-rw-r--r--ext/spl/spl_directory.c3
-rw-r--r--ext/spl/tests/bug70561.phpt23
-rw-r--r--ext/spl/tests/dit_006.phpt12
3 files changed, 32 insertions, 6 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 5090a0b1ac..a330ac42ff 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -834,7 +834,8 @@ SPL_METHOD(DirectoryIterator, seek)
zval_ptr_dtor(&retval);
}
if (!valid) {
- break;
+ zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", pos);
+ return;
}
zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_next, "next", NULL);
}
diff --git a/ext/spl/tests/bug70561.phpt b/ext/spl/tests/bug70561.phpt
new file mode 100644
index 0000000000..c6c229ad89
--- /dev/null
+++ b/ext/spl/tests/bug70561.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #70561 (DirectoryIterator::seek should throw OutOfBoundsException)
+--FILE--
+<?php
+$di = new DirectoryIterator(__DIR__ . '/..');
+
+$cnt = 0;
+$di->rewind();
+while ($di->valid()) {
+ $cnt++;
+ $di->next();
+}
+
+try {
+ $di->seek($cnt+1);
+} catch (OutOfBoundsException $ex) {
+ echo $ex->getMessage() . PHP_EOL;
+}
+echo "Is valid? " . (int) $di->valid() . PHP_EOL;
+?>
+--EXPECTF--
+Seek position %d is out of range
+Is valid? 0
diff --git a/ext/spl/tests/dit_006.phpt b/ext/spl/tests/dit_006.phpt
index 9edbb9f157..ed1ceffc05 100644
--- a/ext/spl/tests/dit_006.phpt
+++ b/ext/spl/tests/dit_006.phpt
@@ -30,11 +30,12 @@ while ($di->valid()) {
echo "Without seek we get $o\n";
-$p = 0;
-$di->seek($o+1);
-while ($di->valid()) {
- $p++;
- $di->next();
+try {
+ $p = 0;
+ $di->seek($o+1);
+ $p = 1;
+} catch (\OutOfBoundsException $ex) {
+ echo $ex->getMessage() . PHP_EOL;
}
var_dump($n !== $m, $m === $o, $p === 0);
@@ -44,6 +45,7 @@ var_dump($n !== $m, $m === $o, $p === 0);
With seek(2) we get %d
With seek(0) we get %d
Without seek we get %d
+Seek position %d is out of range
bool(true)
bool(true)
bool(true)