com php-src: Follow up #77849 PDOStatement objects in undefined state after clone: ext/pdo/pdo_stmt.c ext/pdo/tests/bug_778 49_2.phpt
| From: | Joe Watkins | Date: | Fri, 05 Apr 2019 23:26:47 +0000 |
| Subject: | com php-src: Follow up #77849 PDOStatement objects in undefined state after clone: ext/pdo/pdo_stmt.c ext/pdo/tests/bug_778 49_2.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105538@lists.php.net to get a copy of this message | ||
Commit: a2b8a62abf905f02504c81d7dd868ac83dfc7207
Author: Joe Watkins <krakjoe@php.net> Sat, 6 Apr 2019 01:26:47 +0200
Parents: 9ec1525eb5840f8a38470df65f3a36b43eaf28f0
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a2b8a62abf905f02504c81d7dd868ac83dfc7207
Log:
Follow up #77849 PDOStatement objects in undefined state after clone
Bugs:
https://bugs.php.net/77849
Changed paths:
M ext/pdo/pdo_stmt.c
A ext/pdo/tests/bug_77849_2.phpt
Diff:
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 4baaf80..bf404fc 100644
--- a/ext/pdo/pdo_stmt..c
+++ b/ext/pdo/pdo_stmt.c
@@ -2266,22 +2266,6 @@ static int dbstmt_compare(zval *object1, zval *object2)
return -1;
}
-static zend_object *dbstmt_clone_obj(zval *zobject)
-{
- pdo_stmt_t *stmt;
- pdo_stmt_t *old_stmt;
-
- stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(Z_OBJCE_P(zobject)));
- zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject));
- object_properties_init(&stmt->std, Z_OBJCE_P(zobject));
-
- old_stmt = Z_PDO_STMT_P(zobject);
-
- zend_objects_clone_members(&stmt->std, &old_stmt->std);
-
- return &stmt->std;
-}
-
zend_object_handlers pdo_dbstmt_object_handlers;
static int pdo_row_serialize(zval *object, unsigned char **buffer, size_t *buf_len,
zend_serialize_data *data);
@@ -2304,7 +2288,7 @@ void pdo_stmt_init(void)
pdo_dbstmt_object_handlers.unset_property = dbstmt_prop_delete;
pdo_dbstmt_object_handlers.get_method = dbstmt_method_get;
pdo_dbstmt_object_handlers.compare_objects = dbstmt_compare;
- pdo_dbstmt_object_handlers.clone_obj = dbstmt_clone_obj;
+ pdo_dbstmt_object_handlers.clone_obj = NULL;
INIT_CLASS_ENTRY(ce, "PDORow", pdo_row_functions);
pdo_row_ce = zend_register_internal_class(&ce);
diff --git a/ext/pdo/tests/bug_77849_2.phpt b/ext/pdo/tests/bug_77849_2.phpt
new file mode 100644
index 0000000..53a0735
--- /dev/null
+++ b/ext/pdo/tests/bug_77849_2.phpt
@@ -0,0 +1,18 @@
+--TEST--
+PDO Common: Bug #77849 (inconsistent state of cloned statament object)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo')) die('skip');
+?>
+--FILE--
+<?php
+$stmt = new PDOStatement();
+
+clone $stmt;
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDOStatement in %s:4
+Stack trace:
+#0 {main}
+ thrown in %s on line 4
+