Skip to content

Commit 64a7e46

Browse files
committed
Fixed bug #35797 (segfault on PDOStatement::execute() with
zend.ze1_compatibility_mode = On).
1 parent 34f32d4 commit 64a7e46

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
the callback). (Tony)
1212
- Fixed bug #35817 (unpack() does not decode odd number of hexadecimal values).
1313
(Ilia)
14+
- Fixed bug #35797 (segfault on PDOStatement::execute() with
15+
zend.ze1_compatibility_mode = On). (Tony, Ilia)
1416
- Fixed bug #35781 (stream_filter_append() can cause segfault). (Tony)
1517
- Fixed bug #35759 (mysqli_stmt_bind_result() makes huge allocation when
1618
column empty). (Andrey)

ext/pdo/pdo_stmt.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,34 @@ static int dbstmt_compare(zval *object1, zval *object2 TSRMLS_DC)
20602060
return -1;
20612061
}
20622062

2063+
static zend_object_value dbstmt_clone_obj(zval *zobject TSRMLS_DC)
2064+
{
2065+
zend_object_value retval;
2066+
zval *tmp;
2067+
pdo_stmt_t *stmt;
2068+
pdo_stmt_t *old_stmt;
2069+
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
2070+
2071+
stmt = ecalloc(1, sizeof(*stmt));
2072+
stmt->ce = Z_OBJCE_P(zobject);
2073+
stmt->refcount = 1;
2074+
ALLOC_HASHTABLE(stmt->properties);
2075+
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
2076+
zend_hash_copy(stmt->properties, &stmt->ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
2077+
2078+
old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC);
2079+
2080+
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC);
2081+
retval.handlers = Z_OBJ_HT_P(zobject);
2082+
2083+
zend_objects_clone_members((zend_object *)stmt, retval, (zend_object *)old_stmt, handle TSRMLS_CC);
2084+
2085+
zend_objects_store_add_ref(&old_stmt->database_object_handle TSRMLS_CC);
2086+
stmt->database_object_handle = old_stmt->database_object_handle;
2087+
2088+
return retval;
2089+
}
2090+
20632091
zend_object_handlers pdo_dbstmt_object_handlers;
20642092

20652093
void pdo_stmt_init(TSRMLS_D)
@@ -2078,6 +2106,7 @@ void pdo_stmt_init(TSRMLS_D)
20782106
pdo_dbstmt_object_handlers.unset_property = dbstmt_prop_delete;
20792107
pdo_dbstmt_object_handlers.get_method = dbstmt_method_get;
20802108
pdo_dbstmt_object_handlers.compare_objects = dbstmt_compare;
2109+
pdo_dbstmt_object_handlers.clone_obj = dbstmt_clone_obj;
20812110

20822111
INIT_CLASS_ENTRY(ce, "PDORow", pdo_row_functions);
20832112
pdo_row_ce = zend_register_internal_class(&ce TSRMLS_CC);
@@ -2172,7 +2201,7 @@ zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
21722201
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
21732202
zend_hash_copy(stmt->properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
21742203

2175-
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, NULL TSRMLS_CC);
2204+
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC);
21762205
retval.handlers = &pdo_dbstmt_object_handlers;
21772206

21782207
return retval;

0 commit comments

Comments
 (0)