Skip to content

Commit 42a64b4

Browse files
j6tttaylorr
authored andcommitted
gitk: sanitize 'open' arguments: simple commands with redirections
As in the previous commits, introduce a function that sanitizes arguments intended for the process and in addition allows to pass redirections, which are passed to Tcl's 'open' verbatim. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent fe32bf3 commit 42a64b4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

gitk

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ proc safe_open_command {cmd} {
6666
open |[make_arglist_safe $cmd] r
6767
}
6868

69+
# opens a command pipeline for reading with redirections
70+
# cmd is a list that specifies the command and its arguments
71+
# redir is a list that specifies redirections
72+
# calls `open` and returns the file id
73+
proc safe_open_command_redirect {cmd redir} {
74+
set cmd [make_arglist_safe $cmd]
75+
open |[concat $cmd $redir] r
76+
}
77+
6978
# End exec/open wrappers
7079

7180
proc hasworktree {} {
@@ -9906,8 +9915,8 @@ proc resethead {} {
99069915
bind $w <Visibility> "grab $w; focus $w"
99079916
tkwait window $w
99089917
if {!$confirm_ok} return
9909-
if {[catch {set fd [open \
9910-
[list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9918+
if {[catch {set fd [safe_open_command_redirect \
9919+
[list git reset --$resettype $rowmenuid] [list 2>@1]]} err]} {
99119920
error_popup $err
99129921
} else {
99139922
dohidelocalchanges
@@ -9978,7 +9987,7 @@ proc cobranch {} {
99789987

99799988
# check the tree is clean first??
99809989
set newhead $headmenuhead
9981-
set command [list | git checkout]
9990+
set command [list git checkout]
99829991
if {[string match "remotes/*" $newhead]} {
99839992
set remote $newhead
99849993
set newhead [string range $newhead [expr [string last / $newhead] + 1] end]
@@ -9992,12 +10001,11 @@ proc cobranch {} {
999210001
} else {
999310002
lappend command $newhead
999410003
}
9995-
lappend command 2>@1
999610004
nowbusy checkout [mc "Checking out"]
999710005
update
999810006
dohidelocalchanges
999910007
if {[catch {
10000-
set fd [open $command r]
10008+
set fd [safe_open_command_redirect $command [list 2>@1]]
1000110009
} err]} {
1000210010
notbusy checkout
1000310011
error_popup $err

0 commit comments

Comments
 (0)