From: Olivier Paroz Date: Mon, 26 Jan 2015 11:32:17 +0000 (+0100) Subject: use ExecutableFinder and find in findBinaryPath X-Git-Tag: v8.1.0alpha1~94^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7c41c0c13f1a845fdcedd62218de490e8c01691b;p=nextcloud-server.git use ExecutableFinder and find in findBinaryPath When using open_basedir, commands such as `which`or `command`can fail because they might try to look outside of the restricted perimeter. Symfony's ExecutableFinder can be used instead to look in standard locations and we can use `find` as a last resort A better solution would be to adopt a mechanism similar to what has been done for office documents where a configuration parameter is used to indicate the path where the executable is to be found. --- diff --git a/lib/private/helper.php b/lib/private/helper.php index 099c6def37f..446a6199e2b 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -2,29 +2,28 @@ /** * @author Arthur Schiwon * @author Bart Visscher - * @author Björn Schießle - * @author Christopher Schäpers + * @author Björn Schießle + * @author Christopher Schäpers * @author Fabian Henze * @author Felix Moeller - * @author François Kubler + * @author François Kubler * @author Frank Karlitschek * @author Georg Ehrke - * @author Georg Ehrke * @author Jakob Sack * @author Jan-Christoph Borchardt * @author Joas Schilling - * @author Jörn Friedrich Dreyer + * @author Jörn Friedrich Dreyer * @author Lukas Reschke * @author Michael Gapczynski * @author Morris Jobke - * @author Olivier Paroz + * @author Olivier Paroz * @author Owen Winkler * @author Pellaeon Lin * @author Robin Appelman * @author Robin McCorkell * @author Roeland Jago Douma - * @author Simon Könnecke - * @author Thomas Müller + * @author Simon Könnecke + * @author Thomas Müller * @author Thomas Tanghus * @author Valerio Ponte * @author Vincent Petry @@ -45,6 +44,7 @@ * along with this program. If not, see * */ +use Symfony\Component\Process\ExecutableFinder; /** * Collection of useful functions @@ -921,9 +921,15 @@ class OC_Helper { } $result = null; if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) { - exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); - if ($returnCode === 0 && count($output) > 0) { - $result = escapeshellcmd($output[0]); + $exeSniffer = new ExecutableFinder(); + // Returns null if nothing is found + $result = $exeSniffer->find($program); + if (empty($result)) { + // The order of the folders is important as we'll use the first command we find + exec('find /usr/local/bin/ /usr/bin/ -name ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); + if ($returnCode === 0 && count($output) > 0) { + $result = escapeshellcmd($output[0]); + } } } $memcache->set($program, $result, 3600);