Skip to content

Commit

Permalink
Helpers::getSource() improved escaping of cmdline arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 13, 2019
1 parent e935bdf commit 88ee594
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function getSource(): string
. $_SERVER['REQUEST_URI'];
} else {
return 'CLI (PID: ' . getmypid() . ')'
. (empty($_SERVER['argv']) ? '' : ': ' . implode(' ', $_SERVER['argv']));
. ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv']));
}
}

Expand Down Expand Up @@ -302,4 +302,19 @@ public static function getNonce(): ?string
? $m[1]
: null;
}
/**
* Escape a string to be used as a shell argument.
*/
private static function escapeArg(string $s): string
{
if (preg_match('#^[a-z0-9._=/:-]+\z#i', $s)) {
return $s;
}

return defined('PHP_WINDOWS_VERSION_BUILD')
? '"' . str_replace('"', '""', $s) . '"'
: escapeshellarg($s);
}
}

0 comments on commit 88ee594

Please sign in to comment.