Skip to content

Commit aaf7638

Browse files
committed
Fixed bug #70221 (persistent sqlite connection + custom function segfaults)
1 parent 16f2ce8 commit aaf7638

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #66606 (Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE).
1111
(wusuopu, cmb)
1212

13+
- PDO:
14+
. Fixed bug #70221 (persistent sqlite connection + custom function
15+
segfaults). (Laruence)
16+
1317
- Phpdbg:
1418
. Fixed bug #70214 (FASYNC not defined, needs sys/file.h include). (Bob)
1519

ext/pdo/pdo_dbh.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,15 @@ static void cls_method_dtor(zval *el) /* {{{ */ {
12621262
}
12631263
/* }}} */
12641264

1265+
static void cls_method_pdtor(zval *el) /* {{{ */ {
1266+
zend_function *func = (zend_function*)Z_PTR_P(el);
1267+
if (func->common.function_name) {
1268+
zend_string_release(func->common.function_name);
1269+
}
1270+
pefree(func, 1);
1271+
}
1272+
/* }}} */
1273+
12651274
/* {{{ overloaded object handlers for PDO class */
12661275
int pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
12671276
{
@@ -1283,12 +1292,13 @@ int pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
12831292
if (!(dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent))) {
12841293
php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO methods.");
12851294
}
1286-
zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL, cls_method_dtor, dbh->is_persistent, 0);
1295+
zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL,
1296+
dbh->is_persistent? cls_method_pdtor : cls_method_dtor, dbh->is_persistent, 0);
12871297

12881298
while (funcs->fname) {
12891299
ifunc->type = ZEND_INTERNAL_FUNCTION;
12901300
ifunc->handler = funcs->handler;
1291-
ifunc->function_name = zend_string_init(funcs->fname, strlen(funcs->fname), 0);
1301+
ifunc->function_name = zend_string_init(funcs->fname, strlen(funcs->fname), dbh->is_persistent);
12921302
ifunc->scope = dbh_obj->std.ce;
12931303
ifunc->prototype = NULL;
12941304
if (funcs->flags) {

ext/pdo_sqlite/tests/bug70221.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #70221 (persistent sqlite connection + custom function segfaults)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
6+
?>
7+
--FILE--
8+
<?php
9+
$db = new PDO('sqlite:test.sqlite', null, null, array(PDO::ATTR_PERSISTENT => true));
10+
function _test() { return 42; }
11+
$db->sqliteCreateFunction('test', '_test', 0);
12+
print("Everything is fine, no exceptions here\n");
13+
?>
14+
--EXPECT--
15+
Everything is fine, no exceptions here

0 commit comments

Comments
 (0)