Skip to content

Commit

Permalink
Merge branch 'PHP-8.3' into PHP-8.4
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix cycle leak in sqlite3 setAuthorizer()
  • Loading branch information
nielsdos committed Feb 23, 2025
2 parents 96340e9 + 353f214 commit 7603509
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PHP NEWS
- PDO_SQLite:
. Fixed GH-17837 ()::getColumnMeta() on unexecuted statement segfaults).
(cmb)
. Fix cycle leak in sqlite3 setAuthorizer(). (nielsdos)

- Phar:
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)
Expand Down
4 changes: 3 additions & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2243,14 +2243,16 @@ static HashTable *php_sqlite3_get_gc(zend_object *object, zval **table, int *n)
{
php_sqlite3_db_object *intern = php_sqlite3_db_from_obj(object);

if (intern->funcs == NULL && intern->collations == NULL) {
if (intern->funcs == NULL && intern->collations == NULL && !ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
/* Fast path without allocations */
*table = NULL;
*n = 0;
return zend_std_get_gc(object, table, n);
} else {
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();

php_sqlite3_gc_buffer_add_fcc(gc_buffer, &intern->authorizer_fcc);

php_sqlite3_func *func = intern->funcs;
while (func != NULL) {
php_sqlite3_gc_buffer_add_fcc(gc_buffer, &func->func);
Expand Down
21 changes: 21 additions & 0 deletions ext/sqlite3/tests/setauthorizer_cycle_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
setAuthorizer() cycle leak
--EXTENSIONS--
sqlite3
--FILE--
<?php
class Foo extends Sqlite3 {
public function __construct() {
parent::__construct(":memory:");
$this->setAuthorizer([$this, "foo"]);
}

public function foo() {}
}

$test = new Foo;

echo "Done\n";
?>
--EXPECT--
Done

0 comments on commit 7603509

Please sign in to comment.