diff --git a/ext/sqlite3/tests/sqlite3_trampoline_create_aggregate_no_leak.phpt b/ext/sqlite3/tests/sqlite3_trampoline_create_aggregate_no_leak.phpt new file mode 100644 index 0000000000000..cda9eee278f0f --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_trampoline_create_aggregate_no_leak.phpt @@ -0,0 +1,75 @@ +--TEST-- +SQLite3::createAggregate() trampoline callback +--EXTENSIONS-- +sqlite3 +--FILE-- + 0, 'values' => []]; + } + $context['total'] += (int) $arguments[2]; + $context['values'][] = $context['total']; + return $context; + } +} +$o = new TrampolineTest(); +$step = [$o, 'step']; +$finalize = [$o, 'finalize']; + +echo "Creating Table\n"; +var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)')); + +echo "INSERT into table\n"; +var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)")); +var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)")); + +$db->createAggregate('S', $step, $finalize, 1); + +print_r($db->querySingle("SELECT S(a), S(b) FROM test", true)); + +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; +?> +--EXPECT-- +Creating Table +bool(true) +INSERT into table +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for step +Trampoline for finalize +Trampoline for finalize +Array +( + [S(a)] => 1,3,6,10,14 + [S(b)] => -1,-3,-6,-10,-14 +) +Closing database +bool(true) +Done diff --git a/ext/sqlite3/tests/sqlite3_trampoline_createcollation_no_leak.phpt b/ext/sqlite3/tests/sqlite3_trampoline_createcollation_no_leak.phpt new file mode 100644 index 0000000000000..cf4f00b783829 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_trampoline_createcollation_no_leak.phpt @@ -0,0 +1,33 @@ +--TEST-- +SQLite3::createFunction use F ZPP for trampoline callback and does not leak +--EXTENSIONS-- +sqlite3 +--FILE-- +createfunction('', $callback)); + +try { + var_dump($db->createfunction('strtoupper', $callback, new stdClass())); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +var_dump($db->createfunction('strtoupper', $callback)); + +?> +--EXPECT-- +bool(false) +TypeError: SQLite3::createFunction(): Argument #3 ($argCount) must be of type int, stdClass given +bool(true) diff --git a/ext/sqlite3/tests/sqlite3_trampoline_createfunction_no_leak.phpt b/ext/sqlite3/tests/sqlite3_trampoline_createfunction_no_leak.phpt new file mode 100644 index 0000000000000..cf4f00b783829 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_trampoline_createfunction_no_leak.phpt @@ -0,0 +1,33 @@ +--TEST-- +SQLite3::createFunction use F ZPP for trampoline callback and does not leak +--EXTENSIONS-- +sqlite3 +--FILE-- +createfunction('', $callback)); + +try { + var_dump($db->createfunction('strtoupper', $callback, new stdClass())); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +var_dump($db->createfunction('strtoupper', $callback)); + +?> +--EXPECT-- +bool(false) +TypeError: SQLite3::createFunction(): Argument #3 ($argCount) must be of type int, stdClass given +bool(true) diff --git a/ext/sqlite3/tests/sqlite3_trampoline_setauthorizer_no_leak.phpt b/ext/sqlite3/tests/sqlite3_trampoline_setauthorizer_no_leak.phpt new file mode 100644 index 0000000000000..9a89d36f8e688 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_trampoline_setauthorizer_no_leak.phpt @@ -0,0 +1,41 @@ +--TEST-- +SQLite3 user authorizer trampoline callback +--EXTENSIONS-- +sqlite3 +--FILE-- +enableExceptions(true); + +$db->setAuthorizer($callback); + +// This query should be accepted +var_dump($db->querySingle('SELECT 1;')); + +try { + // This one should fail + var_dump($db->querySingle('CREATE TABLE test (a, b);')); +} catch (\Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECT-- +Trampoline for authorizer +int(1) +Trampoline for authorizer +Unable to prepare statement: not authorized