Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ PHP_METHOD(Phar, webPhar)
char *testit;

testit = sapi_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME")-1);
if (!testit) {
goto finish;
}
if (!(pt = strstr(testit, basename))) {
efree(testit);
goto finish;
Expand Down
31 changes: 31 additions & 0 deletions ext/phar/tests/gh21797.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
GH-21797: Phar::webPhar() NULL dereference when SCRIPT_NAME absent from SAPI environment
--EXTENSIONS--
phar
--INI--
phar.readonly=0
phar.require_hash=0
--FILE--
<?php
// The NULL dereference in the CGI/FastCGI branch of webPhar() is not
// reachable from CLI SAPI. This test exercises the CLI code path as a
// regression baseline and verifies the function behaves correctly when
// called outside an HTTP context.

$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';

$phar = new Phar($fname);
$phar->addFromString('index.php', '<?php echo "ok\n"; ?>');
$phar->setStub('<?php
Phar::webPhar();
__HALT_COMPILER(); ?>');
unset($phar);

// webPhar() with no HTTP context returns silently (no request method set)
include $fname;
echo "no crash\n";
?>
--CLEAN--
<?php @unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
--EXPECT--
no crash
Loading