Skip to content

Commit 1e0a93c

Browse files
j6tttaylorr
authored andcommitted
git-gui: pass redirections as separate argument to _open_stdout_stderr
We are going to treat command arguments and redirections differently to avoid passing arguments that look like redirections to the command accidentally. To do so, it will be necessary to know which arguments are intentional redirections. Rewrite direct callers of _open_stdout_stderr to pass intentional redirections as a second (optional) argument. Passing arbitrary arguments is not safe right now, but we rename it to safe_open_command anyway to avoid having to touch the call sites again later when we make it actually safe. We cannot make the function safe right away because one caller is git_read, which does not yet know which of its arguments are redirections. This is the topic of the next commit. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent dc9ecb1 commit 1e0a93c

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

git-gui.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,10 @@ proc git {args} {
631631
return $result
632632
}
633633

634-
proc _open_stdout_stderr {cmd} {
635-
_trace_exec $cmd
634+
proc safe_open_command {cmd {redir {}}} {
635+
_trace_exec [concat $cmd $redir]
636636
if {[catch {
637-
set fd [open [concat [list | ] $cmd] r]
637+
set fd [open [concat [list | ] $cmd $redir] r]
638638
} err]} {
639639
error $err
640640
}
@@ -646,7 +646,7 @@ proc git_read {cmd} {
646646
set cmdp [_git_cmd [lindex $cmd 0]]
647647
set cmd [lrange $cmd 1 end]
648648

649-
return [_open_stdout_stderr [concat $cmdp $cmd]]
649+
return [safe_open_command [concat $cmdp $cmd]]
650650
}
651651

652652
proc git_read_nice {cmd} {
@@ -657,7 +657,7 @@ proc git_read_nice {cmd} {
657657
set cmdp [_git_cmd [lindex $cmd 0]]
658658
set cmd [lrange $cmd 1 end]
659659

660-
return [_open_stdout_stderr [concat $opt $cmdp $cmd]]
660+
return [safe_open_command [concat $opt $cmdp $cmd]]
661661
}
662662

663663
proc git_write {cmd} {

lib/console.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ method _init {} {
9191
}
9292

9393
method exec {cmd {after {}}} {
94-
lappend cmd 2>@1
9594
if {[lindex $cmd 0] eq {git}} {
95+
lappend cmd 2>@1
9696
set fd_f [git_read [lrange $cmd 1 end]]
9797
} else {
98-
set fd_f [_open_stdout_stderr $cmd]
98+
set fd_f [safe_open_command $cmd [list 2>@1]]
9999
}
100100
fconfigure $fd_f -blocking 0 -translation binary
101101
fileevent $fd_f readable [cb _read $fd_f $after]

lib/mergetool.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ proc merge_tool_start {cmdline target backup stages} {
343343

344344
# Force redirection to avoid interpreting output on stderr
345345
# as an error, and launch the tool
346-
lappend cmdline {2>@1}
346+
set redir [list {2>@1}]
347347

348-
if {[catch { set mtool_fd [_open_stdout_stderr $cmdline] } err]} {
348+
if {[catch { set mtool_fd [safe_open_command $cmdline $redir] } err]} {
349349
delete_temp_files $mtool_tmpfiles
350350
error_popup [mc "Could not start the merge tool:\n\n%s" $err]
351351
return

lib/sshkey.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ proc make_ssh_key {w} {
8585

8686
set cmdline [list sh -c {echo | ssh-keygen -q -t rsa -f ~/.ssh/id_rsa 2>&1}]
8787

88-
if {[catch { set sshkey_fd [_open_stdout_stderr $cmdline] } err]} {
88+
if {[catch { set sshkey_fd [safe_open_command $cmdline] } err]} {
8989
error_popup [mc "Could not start ssh-keygen:\n\n%s" $err]
9090
return
9191
}

lib/tools.tcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ proc tools_exec {fullname} {
130130
}
131131

132132
proc tools_run_silent {cmd after} {
133-
lappend cmd 2>@1
134-
set fd [_open_stdout_stderr $cmd]
133+
set fd [safe_open_command $cmd [list 2>@1]]
135134

136135
fconfigure $fd -blocking 0 -translation binary
137136
fileevent $fd readable [list tools_consume_input $fd $after]

0 commit comments

Comments
 (0)