Issue Bug Under Review

#111640CommandUtility::getCommand() fails for commands only found via which

Markus Hofmann 11/27/26, 12:29 updated 11/27/26, 12:36

Description

Problem

CommandUtility::checkCommand() falls back to which when a command is not found in its search paths (SYS/binPath, SYS/binSetup, /usr/bin/, /usr/local/bin/). That fallback stores the result under the wrong key:

$cmd = @self::exec('which ' . self::escapeShellArgument($cmd), $output, $returnValue);
if ($returnValue === 0) {
    self::$applications[$cmd]['app'] = $cmd;
    self::$applications[$cmd]['path'] = PathUtility::dirname($cmd) . '/';
    self::$applications[$cmd]['valid'] = true;
    return true;
}

$cmd is overwritten with the output of which (e.g. /opt/bin/identify), so the entry is stored under the full path instead of under identify. As a result:

  • checkCommand('identify') returns true, but getCommand('identify') then reads self::$applications['identify'], which does not exist. It logs two warnings and returns an empty string instead of the command:
PHP Warning: Undefined array key "identify" in .../CommandUtility.php line 300
PHP Warning: Trying to access array offset on null in .../CommandUtility.php line 300
  • The entry is never found again, so every call runs which again and logs the warnings again.
  • Even with the correct key, path . app would give /opt/bin//opt/bin/identify, because app holds the full path.

Steps to reproduce

Any command that is on PATH but not in one of the search paths above reaches the fallback. This is typical with open_basedir in effect, where the regular is_executable() check of the search paths fails.

  1. Put an executable mytool into a directory that is on PATH but not configured in SYS/binPath / SYS/binSetup (or enable open_basedir without the binary directory).
  2. Call CommandUtility::checkCommand('mytool'): returns true.
  3. Call CommandUtility::getCommand('mytool').

Actual: two PHP warnings per call, return value ''.

Expected: getCommand('mytool') returns the full path found by which, without warnings, and the second call uses the cached result.

Seen in a TYPO3 14.3.12 installation on shared hosting: an extension calls CommandUtility::getCommand('identify') on each file upload and logs both warnings twice per upload.

Possible fix

Keep the requested name as the key and split the path returned by which:

$path = @self::exec('which ' . self::escapeShellArgument($cmd), $output, $returnValue);
if ($returnValue === 0 && $path !== false && $path !== '') {
    self::$applications[$cmd]['app'] = basename($path);
    self::$applications[$cmd]['path'] = PathUtility::dirname($path) . '/';
    self::$applications[$cmd]['valid'] = true;
    return true;
}

Versions

Affects main, 14.3 and 13.4. The wrong key has been there since at least 2012 (t3lib_exec merged into CommandUtility). Change https://review.typo3.org/c/Packages/TYPO3.CMS/+/79892 (#70869, #85174, “Fix command detection with open_basedir in effect”) replaced the is_executable() check after which with the exit code. This made the fallback reachable under open_basedir, and so the broken entry now shows up there as well.

Related: #70869, #85174

Reviews 1

History 01

  1. Gerrit Code Review pushed patch set 1 for main to change 98106 status New Under Review 11/27/26, 12:36