1
0
Fork 0

Fix php-proxying of binaries to avoid proxying phar files, fixes #9742

pull/9734/head
Jordi Boggiano 2021-03-09 13:57:41 +01:00
parent e9d405ff18
commit 4bedd8379a
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 12 additions and 7 deletions

View File

@ -192,14 +192,18 @@ class BinaryInstaller
$binFile = basename($binPath);
$binContents = file_get_contents($bin);
// For php files, we generate a PHP proxy instead of a shell one,
// which allows calling the proxy with a custom php process
if (preg_match('{^(?:#!(?:/usr)?/bin/env php|#!(?:/usr)?/bin/php|<?php)\r?\n}', $binContents, $match)) {
$proxyCode = trim($match[0]);
// carry over the existing shebang if present, otherwise add our own
if ($proxyCode === "<?php") {
$proxyCode = "#!/usr/bin/env php";
}
$binPathExported = var_export($binPath, true);
return $proxyCode . "\n" . <<<PROXY
// verify the file is not a phar file, because those do not support php-proxying
if (false === ($pos = strpos($binContents, '__HALT_COMPILER')) || false === strpos(substr($binContents, 0, $pos), 'Phar::mapPhar')) {
$proxyCode = trim($match[0]);
// carry over the existing shebang if present, otherwise add our own
if ($proxyCode === "<?php") {
$proxyCode = "#!/usr/bin/env php";
}
$binPathExported = var_export($binPath, true);
return $proxyCode . "\n" . <<<PROXY
<?php
/**
@ -225,6 +229,7 @@ if (\$replaced) {
include \$binPath;
PROXY;
}
}
$proxyCode = <<<PROXY