Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Process] Fix ExecutableFinder with open basedir #11179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/ExecutableFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function addSuffix($suffix)
public function find($name, $default = null, array $extraDirs = array())
{
if (ini_get('open_basedir')) {
$searchPath = explode(PATH_SEPARATOR, getenv('open_basedir'));
$searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
$dirs = array();
foreach ($searchPath as $path) {
if (is_dir($path)) {
Expand Down
112 changes: 112 additions & 0 deletions src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process\Tests;

use Symfony\Component\Process\ExecutableFinder;

/**
* @author Chris Smith <[email protected]>
*/
class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
{
private $path;

public function tearDown()
{
if ($this->path) {
// Restore path if it was changed.
putenv('PATH='.$this->path);
}
}

private function setPath($path)
{
$this->path = getenv('PATH');
putenv('PATH='.$path);
}

public function testFind()
{
if (!defined('PHP_BINARY')) {
$this->markTestSkipped('Requires the PHP_BINARY constant');
}

if (ini_get('open_basedir')) {
$this->markTestSkipped('Cannot test when open_basedir is set');
}

$this->setPath(dirname(PHP_BINARY));

$finder = new ExecutableFinder;
$result = $finder->find(basename(PHP_BINARY));

$this->assertEquals($result, PHP_BINARY);
}

public function testFindWithDefault()
{
if (ini_get('open_basedir')) {
$this->markTestSkipped('Cannot test when open_basedir is set');
}

$expected = 'defaultValue';

$this->setPath('');

$finder = new ExecutableFinder;
$result = $finder->find('foo', $expected);

$this->assertEquals($expected, $result);
}

public function testFindWithExtraDirs()
{
if (!defined('PHP_BINARY')) {
$this->markTestSkipped('Requires the PHP_BINARY constant');
}

if (ini_get('open_basedir')) {
$this->markTestSkipped('Cannot test when open_basedir is set');
}

$this->setPath('');

$extraDirs = array(dirname(PHP_BINARY));

$finder = new ExecutableFinder;
$result = $finder->find(basename(PHP_BINARY), null, $extraDirs);

$this->assertEquals(PHP_BINARY, $result);
}

public function testFindWithOpenBaseDir()
{
if (!defined('PHP_BINARY')) {
$this->markTestSkipped('Requires the PHP_BINARY constant');
}

if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Cannot run test on windows');
}

if (ini_get('open_basedir')) {
$this->markTestSkipped('Cannot test when open_basedir is set');
}

ini_set('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be restored to default value IMO, this is how it's done in every other test touching ini settings etc..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to remove open_basedir restrictions at runtime, hence I permit /.


$finder = new ExecutableFinder;
$result = $finder->find(basename(PHP_BINARY));

$this->assertEquals(PHP_BINARY, $result);
}
}