Skip to content

Commit

Permalink
Merge branch 'bug72788' of https://github.com/keyurdg/php-src into PH…
Browse files Browse the repository at this point in the history
…P-7.0

* 'bug72788' of https://github.com/keyurdg/php-src:
  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.
  • Loading branch information
laruence committed Aug 9, 2016
2 parents 5358c7c + a74c7cb commit ebd21de
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1503,15 +1503,15 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
{
int i;

if (dbh->is_persistent && !free_persistent) {
return;
}

if (dbh->query_stmt) {
zval_ptr_dtor(&dbh->query_stmt_zval);
dbh->query_stmt = NULL;
}

if (dbh->is_persistent && !free_persistent) {
return;
}

if (dbh->methods) {
dbh->methods->closer(dbh);
}
Expand Down
33 changes: 33 additions & 0 deletions ext/pdo/tests/bug_72788.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
PDO Common: Bug #72788 (Invalid memory access when using persistent PDO connection)
--SKIPIF--
<?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';

putenv("PDOTEST_ATTR=" . serialize(array(PDO::ATTR_PERSISTENT => true)));

function test() {
$db = PDOTest::factory('PDO', false);
$stmt = @$db->query("SELECT 1 FROM TABLE_DOES_NOT_EXIST");
if ($stmt === false) {
echo "Statement failed as expected\n";
}
}

test();
test();
echo "Done";
?>
--EXPECT--
Statement failed as expected
Statement failed as expected
Done
4 changes: 2 additions & 2 deletions ext/pdo/tests/pdo_017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ try {
}

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

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/mysql_pdo_test.inc');
$suf = ' ENGINE=' . MySQLPDOTest::detect_transactional_mysql_engine($db);
} else {
$suf = '';
Expand Down
3 changes: 2 additions & 1 deletion ext/pdo_mysql/mysql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
}
#endif

if (IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
if (!Z_ISUNDEF(stmt->database_object_handle)
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
&& (!(GC_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED))) {
while (mysql_more_results(S->H->server)) {
MYSQL_RES *res;
Expand Down
3 changes: 2 additions & 1 deletion ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
zend_bool server_obj_usable = IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
zend_bool server_obj_usable = !Z_ISUNDEF(stmt->database_object_handle)
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
&& !(GC_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED);

if (S->result) {
Expand Down

0 comments on commit ebd21de

Please sign in to comment.