Fix bin proxies to use output buffering instead of the eval hack, as the __FILE__ and __DIR__ replacement is not safe when done in strings/nowdocs/..

main
Jordi Boggiano 3 years ago
parent 44a2aa9be4
commit e1dbd65aff
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -271,21 +271,27 @@ class BinaryInstaller
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path ($binPath) using eval to remove the shebang if present
* This file includes the referenced bin path ($binPath) using ob_start to remove the shebang if present
* to prevent the shebang from being output on PHP<8
*
* @generated
*/
\$binPath = realpath(__DIR__ . "/" . $binPathExported);
if (PHP_VERSION_ID >= 80000) {
include \$binPath;
exit(0);
}
\$contents = file_get_contents(\$binPath);
\$contents = preg_replace('{^#!/.+\\r?\\n<\\?(php)?}', '', \$contents, 1, \$replaced);
if (\$replaced) {
\$contents = strtr(\$contents, array(
'__FILE__' => var_export(\$binPath, true),
'__DIR__' => var_export(dirname(\$binPath), true),
));
ob_start(function (\$buffer, \$phase) {
return (PHP_OUTPUT_HANDLER_START & \$phase) && '#!' === substr(\$buffer, 0, 2) ? '' : \$buffer;
}, 1);
eval(\$contents);
include \$binPath;
exit(0);
}
include \$binPath;

Loading…
Cancel
Save