aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/mw-to-git
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2020-09-21 12:40:00 +0200
committerJunio C Hamano <gitster@pobox.com>2020-09-21 12:37:38 -0700
commit9a8606465e81a04d58c20324c402ba3464bc706a (patch)
tree7a4aa1b4c4da0c6bf3a57486fff2fe035b845149 /contrib/mw-to-git
parent878d150106b0050253390623a8fd5acf553f4be0 (diff)
downloadgit-9a8606465e81a04d58c20324c402ba3464bc706a.tar.gz
remote-mediawiki: use "sh" to eliminate unquoted commands
Remove the use of run_git_unquoted() completely with a use of "sh -c" suggested by Jeff King, i.e.: sh -c '"$@" 2>/dev/null' -- echo sneaky 'argument;id' I don't think this is needed now for any potential RCE issue. The $remotename argument is ultimately picked by the local user (and similarly, the $local variable comes from a user-supplied refspec). But completely eliminating the use of unquoted shell arguments has a value in and of itself, by making the code easier to review. As noted in an earlier commit I think the use of IPC::Open3 would be too verbose here, but this "sh -c" trick strikes the right balance between readability and semantic sanity. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/mw-to-git')
-rwxr-xr-xcontrib/mw-to-git/git-remote-mediawiki.perl24
1 files changed, 8 insertions, 16 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index d21c18df7b..a5624413dc 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -371,8 +371,8 @@ sub get_mw_pages {
# usage: $out = run_git_quoted(["command", "args", ...]);
# $out = run_git_quoted(["command", "args", ...], "raw"); # don't interpret output as UTF-8.
-# $out = run_git_unquoted(["command args"); # don't quote arguments
-# $out = run_git_unquoted(["command args", "raw"); # ditto but raw instead of UTF-8 as above
+# $out = run_git_quoted_nostderr(["command", "args", ...]); # discard stderr
+# $out = run_git_quoted_nostderr(["command", "args", ...], "raw"); # ditto but raw instead of UTF-8 as above
sub _run_git {
my $args = shift;
my $encoding = (shift || 'encoding(UTF-8)');
@@ -391,8 +391,8 @@ sub run_git_quoted {
_run_git(["git", @{$_[0]}], $_[1]);
}
-sub run_git_unquoted {
- _run_git(["git $_[0]"], $_[1]);
+sub run_git_quoted_nostderr {
+ _run_git(['sh', '-c', 'git "$@" 2>/dev/null', '--', @{$_[0]}], $_[1]);
}
sub get_all_mediafiles {
@@ -521,10 +521,8 @@ sub download_mw_mediafile {
sub get_last_local_revision {
# Get note regarding last mediawiki revision.
- #
- # It's OK to use run_git_unquoted() here because $remotename is
- # supplied by the local git itself.
- my $note = run_git_unquoted("notes --ref=${remotename}/mediawiki show refs/mediawiki/${remotename}/master 2>/dev/null");
+ my $note = run_git_quoted_nostderr(["notes", "--ref=${remotename}/mediawiki",
+ "show", "refs/mediawiki/${remotename}/master"]);
my @note_info = split(/ /, $note);
my $lastrevision_number;
@@ -1189,16 +1187,10 @@ sub mw_push_revision {
my $mw_revision = $last_remote_revid;
# Get sha1 of commit pointed by local HEAD
- #
- # It's OK to use run_git_unquoted() because $local is supplied
- # by the local git itself.
- my $HEAD_sha1 = run_git_unquoted("rev-parse ${local} 2>/dev/null");
+ my $HEAD_sha1 = run_git_quoted_nostderr(["rev-parse", $local]);
chomp($HEAD_sha1);
# Get sha1 of commit pointed by remotes/$remotename/master
- #
- # It's OK to use run_git_unquoted() here because $remotename is
- # supplied by the local git itself.
- my $remoteorigin_sha1 = run_git_unquoted("rev-parse refs/remotes/${remotename}/master 2>/dev/null");
+ my $remoteorigin_sha1 = run_git_quoted_nostderr(["rev-parse", "refs/remotes/${remotename}/master"]);
chomp($remoteorigin_sha1);
if ($last_local_revid > 0 &&