]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix dynamic string usage as safe input
authorvrana <jakubv@fb.com>
Sat, 2 Feb 2013 21:07:39 +0000 (13:07 -0800)
committervrana <jakubv@fb.com>
Sun, 3 Feb 2013 00:28:15 +0000 (16:28 -0800)
Summary: This fixes some real issues.

Test Plan:
  $ arc lint

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, btrahan
Differential Revision: https://secure.phabricator.com/D4795

src/difference/ArcanistDiffUtils.php
src/hgdaemon/ArcanistHgProxyServer.php
src/lint/linter/ArcanistJSHintLinter.php
src/lint/linter/ArcanistPyFlakesLinter.php
src/lint/linter/ArcanistPyLintLinter.php
src/parser/ArcanistBaseCommitParser.php
src/parser/ArcanistBundle.php
src/workflow/ArcanistAnoidWorkflow.php
src/workflow/ArcanistDiffWorkflow.php

index 4006235eceb92eb53f306d98d5ae6943562c7def..bff4f63cef5ecd3f6269ab6b4b0b5e7636e6e8cd 100644 (file)
@@ -38,7 +38,9 @@ final class ArcanistDiffUtils {
     Filesystem::writeFile($file_new, (string)$new."\n");
 
     list($err, $stdout) = exec_manual(
-      "/usr/bin/diff {$diff_options} -U {$context_lines} %s %s",
+      '/usr/bin/diff %C -U %s %s %s',
+      $diff_options,
+      $context_lines,
       $file_old,
       $file_new);
 
index 5e41f441023f24ab897e52509f10dbbf53d0c44b..04097cdbc3eb756848065d1cf3918c4c0c2c91a5 100644 (file)
@@ -395,9 +395,8 @@ final class ArcanistHgProxyServer {
     // NOTE: "cmdserver.log=-" makes Mercurial use the 'd'ebug channel for
     // log messages.
 
-    $command = 'HGPLAIN=1 hg --config cmdserver.log=- serve --cmdserver pipe';
-
-    $future = new ExecFuture($command);
+    $future = new ExecFuture(
+      'HGPLAIN=1 hg --config cmdserver.log=- serve --cmdserver pipe');
     $future->setCWD($this->workingCopy);
 
     $channel = new PhutilExecChannel($future);
index 7aa9c5617e08dbd0a83908325a5d97b27129a9e7..ac6ecc3187ceeaa649a8aa44b75ad8673297e396 100644 (file)
@@ -102,8 +102,10 @@ final class ArcanistJSHintLinter extends ArcanistLinter {
     }
 
     // Look for globally installed JSHint
-    $cmd = (phutil_is_windows()) ? 'where %s' : 'which %s';
-    list($err) = exec_manual($cmd, $bin);
+    list($err) = (phutil_is_windows()
+      ? exec_manual('where %s', $bin)
+      : exec_manual('which %s', $bin));
+
     if ($err) {
       throw new ArcanistUsageException(
         "JSHint does not appear to be installed on this system. Install it ".
index 3ae6cdc3d4f81fa20224d4a67e468caf974143b7..99c867a1ee6179092e8fe283215e17e1bd535606 100644 (file)
@@ -60,8 +60,10 @@ final class ArcanistPyFlakesLinter extends ArcanistLinter {
     $options = $this->getPyFlakesOptions();
 
     $f = new ExecFuture(
-          "/usr/bin/env PYTHONPATH=%s\$PYTHONPATH ".
-            "{$pyflakes_bin} {$options}", $python_path);
+      '/usr/bin/env PYTHONPATH=%s$PYTHONPATH %s %C',
+      $python_path,
+      $pyflakes_bin,
+      $options);
     $f->write($this->getData($path));
 
     try {
index 88b45c18673e8f18e000642d5feb0fc95a517917..ad885fb0f235cde639b717d67055a3c761d5f0bb 100644 (file)
@@ -206,9 +206,11 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
 
     try {
       list($stdout, $_) = execx(
-          "/usr/bin/env PYTHONPATH=%s\$PYTHONPATH ".
-            "{$pylint_bin} {$options} {$path_on_disk}",
-          $python_path);
+        '/usr/bin/env PYTHONPATH=%s$PYTHONPATH %s %C %s',
+        $python_path,
+        $pylint_bin,
+        $options,
+        $path_on_disk);
     } catch (CommandException $e) {
       if ($e->getError() == 32) {
         // According to ##man pylint## the exit status of 32 means there was a
index 215e9ee14589ed5c4f7252226b54f2b2859557e8..24cf6c73148642cca748f809f0f71651c833f488 100644 (file)
@@ -157,7 +157,7 @@ final class ArcanistBaseCommitParser {
         $matches = null;
         if (preg_match('/^exec\((.*)\)$/', $name, $matches)) {
           $root = $this->api->getWorkingCopyIdentity()->getProjectRoot();
-          $future = new ExecFuture($matches[1]);
+          $future = new ExecFuture('%C', $matches[1]);
           $future->setCWD($root);
           list($err, $stdout) = $future->resolve();
           if (!$err) {
index 9218675d59f29204bef8c69b99633cc1d7c2e625..c0000c9f512878f40b87578653f29d0cceb39900 100644 (file)
@@ -101,17 +101,15 @@ final class ArcanistBundle {
     $path = Filesystem::resolvePath($path);
 
     $future = new ExecFuture(
-      csprintf(
-        'tar tfO %s',
-        $path));
+      'tar tfO %s',
+      $path);
     list($stdout, $file_list) = $future->resolvex();
     $file_list = explode("\n", trim($file_list));
 
     if (in_array('meta.json', $file_list)) {
       $future = new ExecFuture(
-        csprintf(
-          'tar xfO %s meta.json',
-          $path));
+        'tar xfO %s meta.json',
+        $path);
       $meta_info = $future->resolveJSON();
       $version       = idx($meta_info, 'version', 0);
       $project_name  = idx($meta_info, 'projectName');
@@ -130,9 +128,8 @@ final class ArcanistBundle {
     }
 
     $future = new ExecFuture(
-      csprintf(
-        'tar xfO %s changes.json',
-        $path));
+      'tar xfO %s changes.json',
+      $path);
     $changes = $future->resolveJSON();
 
     foreach ($changes as $change_key => $change) {
index 4a114ea0cde2230880bb9bb98d9088570d3d69f7..91793891aabbd0f0cf80b6595d3a84d90efcca36 100644 (file)
@@ -25,8 +25,8 @@ EOTEXT
 
   public function run() {
     phutil_passthru(
-      dirname(phutil_get_library_root('arcanist')) . '/scripts/breakout.py'
-    );
+      '%s/scripts/breakout.py',
+      dirname(phutil_get_library_root('arcanist')));
   }
 
 }
index 374217b99f0f596feaa962b3e16ef0a00733ae05..f6862cbd8cbd3a5b337d2f19084d9e117440cbdf 100644 (file)
@@ -868,7 +868,7 @@ EOTEXT
         fwrite(STDERR, "Reading diff from stdin...\n");
         $raw_diff = file_get_contents('php://stdin');
       } else if ($this->getArgument('raw-command')) {
-        list($raw_diff) = execx($this->getArgument('raw-command'));
+        list($raw_diff) = execx('%C', $this->getArgument('raw-command'));
       } else {
         throw new Exception("Unknown raw diff source.");
       }