Skip to content

Commit 3f1e9ed

Browse files
committedAug 9, 2016
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed bug #72788 (Invalid memory access when using persistent PDO connection) Remove typo'd commit Fix bug 72788: Invalid memory access when database_object_handle is undefined. Also fix memory leak in dbh_free when using persistent PDO connections.
2 parents 2ece5de + e52cb18 commit 3f1e9ed

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed
 

‎ext/pdo/pdo_dbh.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1499,15 +1499,15 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
14991499
{
15001500
int i;
15011501

1502-
if (dbh->is_persistent && !free_persistent) {
1503-
return;
1504-
}
1505-
15061502
if (dbh->query_stmt) {
15071503
zval_ptr_dtor(&dbh->query_stmt_zval);
15081504
dbh->query_stmt = NULL;
15091505
}
15101506

1507+
if (dbh->is_persistent && !free_persistent) {
1508+
return;
1509+
}
1510+
15111511
if (dbh->methods) {
15121512
dbh->methods->closer(dbh);
15131513
}

‎ext/pdo/tests/bug_72788.phpt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
PDO Common: Bug #72788 (Invalid memory access when using persistent PDO connection)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo')) die('skip');
6+
$dir = getenv('REDIR_TEST_DIR');
7+
if (false == $dir) die('skip no driver');
8+
require_once $dir . 'pdo_test.inc';
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
14+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15+
16+
putenv("PDOTEST_ATTR=" . serialize(array(PDO::ATTR_PERSISTENT => true)));
17+
18+
function test() {
19+
$db = PDOTest::factory('PDO', false);
20+
$stmt = @$db->query("SELECT 1 FROM TABLE_DOES_NOT_EXIST");
21+
if ($stmt === false) {
22+
echo "Statement failed as expected\n";
23+
}
24+
}
25+
26+
test();
27+
test();
28+
echo "Done";
29+
?>
30+
--EXPECT--
31+
Statement failed as expected
32+
Statement failed as expected
33+
Done

‎ext/pdo/tests/pdo_017.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ try {
1616
}
1717

1818
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
19-
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
19+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/mysql_pdo_test.inc');
2020
if (false === MySQLPDOTest::detect_transactional_mysql_engine($db)) {
2121
die('skip your mysql configuration does not support working transactions');
2222
}
@@ -29,7 +29,7 @@ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
2929
$db = PDOTest::factory();
3030

3131
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
32-
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
32+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/mysql_pdo_test.inc');
3333
$suf = ' ENGINE=' . MySQLPDOTest::detect_transactional_mysql_engine($db);
3434
} else {
3535
$suf = '';

‎ext/pdo_mysql/mysql_statement.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
8888
}
8989
#endif
9090

91-
if (IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
91+
if (!Z_ISUNDEF(stmt->database_object_handle)
92+
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
9293
&& (!(GC_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED))) {
9394
while (mysql_more_results(S->H->server)) {
9495
MYSQL_RES *res;

‎ext/pdo_pgsql/pgsql_statement.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
6262
{
6363
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
64-
zend_bool server_obj_usable = IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
64+
zend_bool server_obj_usable = !Z_ISUNDEF(stmt->database_object_handle)
65+
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
6566
&& !(GC_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED);
6667

6768
if (S->result) {

0 commit comments

Comments
 (0)