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

main
Jordi Boggiano 4 years ago
parent e9d405ff18
commit 4bedd8379a
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

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

Loading…
Cancel
Save