diff options
author | Keyur <kgovande@etsy.com> | 2016-08-08 23:34:00 +0000 |
---|---|---|
committer | Keyur <kgovande@etsy.com> | 2016-08-09 00:16:46 +0000 |
commit | 3f25c4228a8f505a000c1ea5751062606247349a (patch) | |
tree | 05caf1efdb75d6704da598e1de007e391420bf40 /ext/pdo | |
parent | be77ce37fd3290365a359f7143cc636d66f14cf1 (diff) | |
download | php-git-3f25c4228a8f505a000c1ea5751062606247349a.tar.gz |
Fix bug 72788: Invalid memory access when database_object_handle
is undefined. Also fix memory leak in dbh_free when using persistent
PDO connections.
Diffstat (limited to 'ext/pdo')
-rw-r--r-- | ext/pdo/pdo_dbh.c | 8 | ||||
-rw-r--r-- | ext/pdo/tests/bug_72788.phpt | 33 | ||||
-rw-r--r-- | ext/pdo/tests/pdo_017.phpt | 4 |
3 files changed, 39 insertions, 6 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 2fb5334a9d..8a7c1d3931 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -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); } diff --git a/ext/pdo/tests/bug_72788.phpt b/ext/pdo/tests/bug_72788.phpt new file mode 100644 index 0000000000..80609a21ba --- /dev/null +++ b/ext/pdo/tests/bug_72788.phpt @@ -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 diff --git a/ext/pdo/tests/pdo_017.phpt b/ext/pdo/tests/pdo_017.phpt index 31ee88b76b..2b8568fb46 100644 --- a/ext/pdo/tests/pdo_017.phpt +++ b/ext/pdo/tests/pdo_017.phpt @@ -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'); } @@ -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 = ''; |