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

Skip to content

Issue with ExecutableFinder with file paths in basedir #11421

Closed
@jess-sol

Description

@jess-sol

The Process component has an ExecutableFinder class which fails in a specific set of circumstances. Below are the steps to recreate the issue.

  1. Set a basedir, make sure one of the paths is to an executable (i.e. /usr/local/bin/someexec)
  2. Attempt to locate the executable.
$execFinder = new Symfony\Component\Process\ExecutableFinder;
echo $execFinder->find('someexec', false);

Because a basedir is set, the ExectuableFinder will enumerate the basedir paths looking for the executable. If the basedir path being enumerated is a directory it is added to an array of directories to search through, if it's a file the name of the file is compared against the name of the executable being searched for. If the names match, it is returned.

The issue occurs because the code being used to compare a filename found in the basedir to the name of the executable being searched for is flawed. Currently the code looks similar to this:

$file = str_replace(dirname($path), '', $path);
if ($file == $name && is_executable($path)) {
    return $path;
}

(Snippet Found Here)

If $path is equal to /usr/local/bin/someexec then dirname($path) will equal /usr/local/bin; this means $file equals /someexec which can never match the executable name which is just someexec.
There are two potential fixes: wrap the assigned $file value with ltrim($file, DIRECTORY_SEPARATOR), or replace the $file = ... line with $file = basename($path);.

I'll make a quick pull request for it if one of the current maintainers agrees this is a bug, and I'm not just doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions