Merge branch 'PHP-7.0'

* PHP-7.0:
  Fix bug #64172
  Fix bug #64172
  Bug #70561: Fix DirectoryIterator to throw OutOfBoundsException
This commit is contained in:
Stanislav Malyshev committed 2015-10-18 17:20:17 -07:00
commit 620daef1e2
6 files changed
+121 -8

No files matched your search

+3
View File
@@ -1016,14 +1016,17 @@ static PHP_METHOD(PDO, errorInfo)
if (dbh->query_stmt) {
add_next_index_string(return_value, dbh->query_stmt->error_code);
if(!strncmp(dbh->query_stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array;
} else {
add_next_index_string(return_value, dbh->error_code);
if(!strncmp(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array;
}
if (dbh->methods->fetch_err) {
dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value);
}
fill_array:
/**
* In order to be consistent, we have to make sure we add the good amount
* of nulls depending on the current number of elements. We make a simple
+84
View File
@@ -0,0 +1,84 @@
--TEST--
PDO Common: Bug #64172 errorInfo is not properly cleaned up
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
@$db->exec("DROP TABLE test");
$db->exec("CREATE TABLE test (x int)");
$db->exec("INSERT INTO test VALUES (1)");
echo "===FAIL===\n";
$db->query('SELECT * FROM bad_table');
echo "\n";
echo "===TEST===\n";
var_dump(is_string($db->errorInfo()[0])) . "\n";
var_dump(is_int($db->errorInfo()[1])) . "\n";
var_dump(is_string($db->errorInfo()[2])) . "\n";
echo "===GOOD===\n";
$stmt = $db->query('SELECT * FROM test');
$stmt->fetchAll();
$stmt = null;
var_dump($db->errorInfo());
echo "===FAIL===\n";
$db->exec("INSERT INTO bad_table VALUES(1)");
echo "\n";
echo "===TEST===\n";
var_dump(is_string($db->errorInfo()[0])) . "\n";
var_dump(is_int($db->errorInfo()[1])) . "\n";
var_dump(is_string($db->errorInfo()[2])) . "\n";
echo "===GOOD===\n";
$db->exec("INSERT INTO test VALUES (2)");
var_dump($db->errorInfo());
$db->exec("DROP TABLE test");
?>
===DONE===
--EXPECTF--
===FAIL===
Warning: PDO::query(): SQLSTATE[%s]: %s
%A
===TEST===
bool(true)
bool(true)
bool(true)
===GOOD===
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
===FAIL===
Warning: PDO::exec(): SQLSTATE[%s]: %s
%A
===TEST===
bool(true)
bool(true)
bool(true)
===GOOD===
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
===DONE===
@@ -129,8 +129,8 @@ array(3) {
[0]=>
%unicode|string%(5) "00000"
[1]=>
int(1146)
NULL
[2]=>
%unicode|string%(%d) "Table '%s.ihopeitdoesnotexist' doesn't exist"
NULL
}
done!
+2 -1
View File
@@ -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);
}
+23
View File
@@ -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
+7 -5
View File
@@ -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)