From e44cd2584887bf975aab6f0e1b5bbbe32a1419e8 Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Fri, 5 Apr 2019 13:42:04 -0500 Subject: [PATCH 1/3] Disable cloning of PDO handle/connection objects to avoid segfault --- ext/pdo/pdo_dbh.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 314c845ac43a8..5ce220ac205ee 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -1403,6 +1403,7 @@ void pdo_dbh_init(void) pdo_dbh_object_handlers.offset = XtOffsetOf(pdo_dbh_object_t, std); pdo_dbh_object_handlers.dtor_obj = zend_objects_destroy_object; pdo_dbh_object_handlers.free_obj = pdo_dbh_free_storage; + pdo_dbh_object_handlers.clone_obj = NULL; pdo_dbh_object_handlers.get_method = dbh_method_get; pdo_dbh_object_handlers.compare_objects = dbh_compare; pdo_dbh_object_handlers.get_gc = dbh_get_gc; From f2145e6e3fd45f64059a1aa9457dc51f7e754f5b Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Fri, 5 Apr 2019 14:39:37 -0500 Subject: [PATCH 2/3] Add test for ensuring cloning PDO objects causes a fatal error. --- ext/pdo/tests/bug_77849.phpt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ext/pdo/tests/bug_77849.phpt diff --git a/ext/pdo/tests/bug_77849.phpt b/ext/pdo/tests/bug_77849.phpt new file mode 100644 index 0000000000000..0b0aad6e92125 --- /dev/null +++ b/ext/pdo/tests/bug_77849.phpt @@ -0,0 +1,35 @@ +--TEST-- +PDO Common: Bug #77849 (Unexpected segfault attempting to use cloned PDO object) +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE test(id INT NULL)'); + +$stmt = $db->query('SELECT * FROM test'); +var_dump($stmt->fetchAll()); + +$db2 = clone $db; + +$stmt2 = $db2->query('SELECT * FROM test'); +var_dump($stmt2->fetchAll()); + +?> +--EXPECTF-- +array(0) { +} + +Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDO in %s +Stack trace: +#0 {main} + thrown in %s on line %d From 802f39d39c841cee27083c40d5f599ca78542bb8 Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Fri, 5 Apr 2019 17:44:06 -0500 Subject: [PATCH 3/3] Remove unnecessary querying in test --- ext/pdo/tests/bug_77849.phpt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ext/pdo/tests/bug_77849.phpt b/ext/pdo/tests/bug_77849.phpt index 0b0aad6e92125..6643f8c581305 100644 --- a/ext/pdo/tests/bug_77849.phpt +++ b/ext/pdo/tests/bug_77849.phpt @@ -14,21 +14,9 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); -$db->exec('CREATE TABLE test(id INT NULL)'); - -$stmt = $db->query('SELECT * FROM test'); -var_dump($stmt->fetchAll()); - $db2 = clone $db; - -$stmt2 = $db2->query('SELECT * FROM test'); -var_dump($stmt2->fetchAll()); - ?> --EXPECTF-- -array(0) { -} - Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDO in %s Stack trace: #0 {main}