-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
239 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
ext/sqlite3/tests/sqlite3_trampoline_create_aggregate_no_leak.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--TEST-- | ||
SQLite3::createAggregate() use F ZPP for trampoline callback and does not leak | ||
--EXTENSIONS-- | ||
sqlite3 | ||
--FILE-- | ||
<?php | ||
|
||
require_once(__DIR__ . '/new_db.inc'); | ||
|
||
class TrampolineTest { | ||
public function __call(string $name, array $arguments) { | ||
echo 'Trampoline for ', $name, PHP_EOL; | ||
$context = $arguments[0]; | ||
if ($name === 'finalize') { | ||
return implode(',', $context['values']); | ||
} | ||
if (empty($context)) { | ||
$context = ['total' => 0, 'values' => []]; | ||
} | ||
$context['total'] += (int) $arguments[2]; | ||
$context['values'][] = $context['total']; | ||
return $context; | ||
} | ||
} | ||
$o = new TrampolineTest(); | ||
$step = [$o, 'step']; | ||
$finalize = [$o, 'finalize']; | ||
|
||
var_dump($db->createAggregate('', $step, $finalize, 1)); | ||
|
||
try { | ||
var_dump($db->createAggregate('S', $step, $finalize, new stdClass())); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($db->createAggregate('S', $step, 'no_func', 1)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
try { | ||
var_dump($db->createAggregate('S', 'no_func', $finalize, 1)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
echo "Invalid SQLite3 object:\n"; | ||
$rc = new ReflectionClass(SQLite3::class); | ||
$obj = $rc->newInstanceWithoutConstructor(); | ||
|
||
try { | ||
var_dump($obj->createAggregate('S', $step, $finalize, 1)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
var_dump($db->createAggregate('S', $step, $finalize, 1)); | ||
|
||
echo "Closing database\n"; | ||
var_dump($db->close()); | ||
echo "Done\n"; | ||
?> | ||
--EXPECT-- | ||
bool(false) | ||
TypeError: SQLite3::createAggregate(): Argument #4 ($argCount) must be of type int, stdClass given | ||
TypeError: SQLite3::createAggregate(): Argument #3 ($finalCallback) must be a valid callback, function "no_func" not found or invalid function name | ||
TypeError: SQLite3::createAggregate(): Argument #2 ($stepCallback) must be a valid callback, function "no_func" not found or invalid function name | ||
Invalid SQLite3 object: | ||
Error: The SQLite3 object has not been correctly initialised or is already closed | ||
bool(true) | ||
Closing database | ||
bool(true) | ||
Done |
44 changes: 44 additions & 0 deletions
44
ext/sqlite3/tests/sqlite3_trampoline_createcollation_no_leak.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--TEST-- | ||
SQLite3::createFunction use F ZPP for trampoline callback and does not leak | ||
--EXTENSIONS-- | ||
sqlite3 | ||
--FILE-- | ||
<?php | ||
|
||
require_once(__DIR__ . '/new_db.inc'); | ||
|
||
class TrampolineTest { | ||
public function __call(string $name, array $arguments) { | ||
echo 'Trampoline for ', $name, PHP_EOL; | ||
return strnatcmp(...$arguments); | ||
} | ||
} | ||
$o = new TrampolineTest(); | ||
$callback = [$o, 'NAT']; | ||
|
||
var_dump($db->createCollation('', $callback)); | ||
try { | ||
var_dump($db->createCollation('NAT', $callback, new stdClass())); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
echo "Invalid SQLite3 object:\n"; | ||
$rc = new ReflectionClass(SQLite3::class); | ||
$obj = $rc->newInstanceWithoutConstructor(); | ||
|
||
try { | ||
var_dump($obj->createCollation('NAT', $callback)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
var_dump($db->createCollation('NAT', $callback)); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(false) | ||
ArgumentCountError: SQLite3::createCollation() expects exactly 2 arguments, 3 given | ||
Invalid SQLite3 object: | ||
Error: The SQLite3 object has not been correctly initialised or is already closed | ||
bool(true) |
45 changes: 45 additions & 0 deletions
45
ext/sqlite3/tests/sqlite3_trampoline_createfunction_no_leak.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--TEST-- | ||
SQLite3::createFunction use F ZPP for trampoline callback and does not leak | ||
--EXTENSIONS-- | ||
sqlite3 | ||
--FILE-- | ||
<?php | ||
|
||
require_once(__DIR__ . '/new_db.inc'); | ||
|
||
class TrampolineTest { | ||
public function __call(string $name, array $arguments) { | ||
echo 'Trampoline for ', $name, PHP_EOL; | ||
return strtoupper($arguments[0]); | ||
} | ||
} | ||
$o = new TrampolineTest(); | ||
$callback = [$o, 'strtoupper']; | ||
|
||
var_dump($db->createfunction('', $callback)); | ||
|
||
try { | ||
var_dump($db->createfunction('strtoupper', $callback, new stdClass())); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
echo "Invalid SQLite3 object:\n"; | ||
$rc = new ReflectionClass(SQLite3::class); | ||
$obj = $rc->newInstanceWithoutConstructor(); | ||
|
||
try { | ||
var_dump($obj->createfunction('strtoupper', $callback)); | ||
} 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 | ||
Invalid SQLite3 object: | ||
Error: The SQLite3 object has not been correctly initialised or is already closed | ||
bool(true) |
41 changes: 41 additions & 0 deletions
41
ext/sqlite3/tests/sqlite3_trampoline_setauthorizer_no_leak.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
SQLite3::setAuthorizer use F ZPP for trampoline callback and does not leak | ||
--EXTENSIONS-- | ||
sqlite3 | ||
--FILE-- | ||
<?php | ||
|
||
class TrampolineTest { | ||
public function __call(string $name, array $arguments) { | ||
echo 'Trampoline for ', $name, PHP_EOL; | ||
if ($arguments[0] == SQLite3::SELECT) { | ||
return SQLite3::OK; | ||
} | ||
|
||
return SQLite3::DENY; | ||
} | ||
} | ||
$o = new TrampolineTest(); | ||
$callback = [$o, 'authorizer']; | ||
|
||
$db = new SQLite3(':memory:'); | ||
$db->enableExceptions(true); | ||
|
||
echo "Invalid SQLite3 object:\n"; | ||
$rc = new ReflectionClass(SQLite3::class); | ||
$obj = $rc->newInstanceWithoutConstructor(); | ||
|
||
try { | ||
var_dump($obj->setAuthorizer($callback)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
$db->setAuthorizer($callback); | ||
|
||
?> | ||
DONE | ||
--EXPECT-- | ||
Invalid SQLite3 object: | ||
Error: The SQLite3 object has not been correctly initialised or is already closed | ||
DONE |