prevent user from executing phar stub file directly

This commit is contained in:
crazywhalecc 2022-05-04 17:43:15 +08:00
parent 396444a089
commit a934037179
2 changed files with 7 additions and 0 deletions

View File

@ -11,3 +11,4 @@ parameters:
dynamicConstantNames:
- SWOOLE_VERSION
- ZM_TEST_LOG_DEBUG
- _PHAR_STUB_ID

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
const _PHAR_STUB_ID = '__generated_id__';
function loader__generated_id__()
{
$obj = json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true);
@ -12,4 +14,8 @@ function loader__generated_id__()
require_once Phar::running() . '/' . $v;
}
}
if ('__generate' . 'd_id__' === _PHAR_STUB_ID) {
echo 'Cannot execute this file directly!' . PHP_EOL;
exit(1);
}
return json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true) ?? ['zm_module' => false];