#208 improved GPG open_basedir

This commit is contained in:
the-djmaze 2022-02-03 22:48:11 +01:00
parent 25d946b873
commit ad269597d6

View file

@ -1381,7 +1381,6 @@ class GPG
private static function findBinary($name) : ?string private static function findBinary($name) : ?string
{ {
if (!\ini_get('open_basedir')) {
$binary = \trim(`which $name`); $binary = \trim(`which $name`);
if ($binary && \is_executable($binary)) { if ($binary && \is_executable($binary)) {
return $binary; return $binary;
@ -1393,12 +1392,23 @@ class GPG
'/opt/local/bin/', '/opt/local/bin/',
'/run/current-system/sw/bin/' '/run/current-system/sw/bin/'
]; ];
$open_basedir = \ini_get('open_basedir');
if ($open_basedir) {
$open_basedir = \explode(PATH_SEPARATOR, $open_basedir);
$locations = \array_filter($locations, function($path) use ($open_basedir) {
foreach ($open_basedir as $dir) {
if (\str_starts_with($path, $open_basedir)) {
return true;
}
}
return false;
});
}
foreach ($locations as $location) { foreach ($locations as $location) {
if (\is_executable($location . $name)) { if (\is_executable($location . $name)) {
return $location . $name; return $location . $name;
} }
} }
}
return null; return null;
} }