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>
			
			
				maint
			
			
		
							parent
							
								
									878d150106
								
							
						
					
					
						commit
						9a8606465e
					
				|  | @ -371,8 +371,8 @@ sub get_mw_pages { | ||||||
|  |  | ||||||
| # usage: $out = run_git_quoted(["command", "args", ...]); | # usage: $out = run_git_quoted(["command", "args", ...]); | ||||||
| #        $out = run_git_quoted(["command", "args", ...], "raw"); # don't interpret output as UTF-8. | #        $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_quoted_nostderr(["command", "args", ...]); # discard stderr | ||||||
| #        $out = run_git_unquoted(["command args", "raw"); # ditto but raw instead of UTF-8 as above | #        $out = run_git_quoted_nostderr(["command", "args", ...], "raw"); # ditto but raw instead of UTF-8 as above | ||||||
| sub _run_git { | sub _run_git { | ||||||
| 	my $args = shift; | 	my $args = shift; | ||||||
| 	my $encoding = (shift || 'encoding(UTF-8)'); | 	my $encoding = (shift || 'encoding(UTF-8)'); | ||||||
|  | @ -391,8 +391,8 @@ sub run_git_quoted { | ||||||
|     _run_git(["git", @{$_[0]}], $_[1]); |     _run_git(["git", @{$_[0]}], $_[1]); | ||||||
| } | } | ||||||
|  |  | ||||||
| sub run_git_unquoted { | sub run_git_quoted_nostderr { | ||||||
|     _run_git(["git $_[0]"], $_[1]); |     _run_git(['sh', '-c', 'git "$@" 2>/dev/null', '--', @{$_[0]}], $_[1]); | ||||||
| } | } | ||||||
|  |  | ||||||
| sub get_all_mediafiles { | sub get_all_mediafiles { | ||||||
|  | @ -521,10 +521,8 @@ sub download_mw_mediafile { | ||||||
|  |  | ||||||
| sub get_last_local_revision { | sub get_last_local_revision { | ||||||
| 	# Get note regarding last mediawiki revision. | 	# Get note regarding last mediawiki revision. | ||||||
| 	# | 	my $note = run_git_quoted_nostderr(["notes", "--ref=${remotename}/mediawiki", | ||||||
| 	# It's OK to use run_git_unquoted() here because $remotename is | 					    "show", "refs/mediawiki/${remotename}/master"]); | ||||||
| 	# 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_info = split(/ /, $note); | 	my @note_info = split(/ /, $note); | ||||||
|  |  | ||||||
| 	my $lastrevision_number; | 	my $lastrevision_number; | ||||||
|  | @ -1189,16 +1187,10 @@ sub mw_push_revision { | ||||||
| 	my $mw_revision = $last_remote_revid; | 	my $mw_revision = $last_remote_revid; | ||||||
|  |  | ||||||
| 	# Get sha1 of commit pointed by local HEAD | 	# Get sha1 of commit pointed by local HEAD | ||||||
| 	# | 	my $HEAD_sha1 = run_git_quoted_nostderr(["rev-parse", $local]); | ||||||
| 	# 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"); |  | ||||||
| 	chomp($HEAD_sha1); | 	chomp($HEAD_sha1); | ||||||
| 	# Get sha1 of commit pointed by remotes/$remotename/master | 	# Get sha1 of commit pointed by remotes/$remotename/master | ||||||
| 	# | 	my $remoteorigin_sha1 = run_git_quoted_nostderr(["rev-parse", "refs/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"); |  | ||||||
| 	chomp($remoteorigin_sha1); | 	chomp($remoteorigin_sha1); | ||||||
|  |  | ||||||
| 	if ($last_local_revid > 0 && | 	if ($last_local_revid > 0 && | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Ævar Arnfjörð Bjarmason
						Ævar Arnfjörð Bjarmason