Skip to content

Commit 6b631ee

Browse files
j6tttaylorr
authored andcommitted
gitk: sanitize 'exec' arguments: redirections
As in the previous commits, introduce a function that sanitizes arguments intended for the process and in addition allows to pass redirections verbatim, which are interpreted by Tcl's 'exec'. Redirections can include the background operator '&'. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 88139a6 commit 6b631ee

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

gitk

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ proc safe_exec {cmd} {
4040
eval exec [make_arglist_safe $cmd]
4141
}
4242

43+
# executes one command with redirections
44+
# no pipelines are possible
45+
# cmd is a list that specifies the command and its arguments
46+
# redir is a list that specifies redirections (output, background)
47+
# calls `exec` and returns its value
48+
proc safe_exec_redirect {cmd redir} {
49+
eval exec [make_arglist_safe $cmd] $redir
50+
}
51+
4352
proc safe_open_file {filename flags} {
4453
# a file name starting with "|" would attempt to run a process
4554
# but such a file name must be treated as a relative path
@@ -2135,7 +2144,7 @@ proc makewindow {} {
21352144
{mc "Reread re&ferences" command rereadrefs}
21362145
{mc "&List references" command showrefs -accelerator F2}
21372146
{xx "" separator}
2138-
{mc "Start git &gui" command {exec git gui &}}
2147+
{mc "Start git &gui" command {safe_exec_redirect [list git gui] [list &]}}
21392148
{xx "" separator}
21402149
{mc "&Quit" command doquit -accelerator Meta1-Q}
21412150
}}
@@ -3655,7 +3664,7 @@ proc gitknewtmpdir {} {
36553664
proc save_file_from_commit {filename output what} {
36563665
global nullfile
36573666

3658-
if {[catch {exec git show $filename -- > $output} err]} {
3667+
if {[catch {safe_exec_redirect [list git show $filename --] [list > $output]} err]} {
36593668
if {[string match "fatal: bad revision *" $err]} {
36603669
return $nullfile
36613670
}
@@ -3884,7 +3893,7 @@ proc external_blame {parent_idx {line {}}} {
38843893
# being given an absolute path...
38853894
set f [make_relative $f]
38863895
lappend cmdline $base_commit $f
3887-
if {[catch {eval exec $cmdline &} err]} {
3896+
if {[catch {safe_exec_redirect $cmdline [list &]} err]} {
38883897
error_popup "[mc "git gui blame: command failed:"] $err"
38893898
}
38903899
}
@@ -7193,8 +7202,8 @@ proc browseweb {url} {
71937202
global web_browser
71947203

71957204
if {$web_browser eq {}} return
7196-
# Use eval here in case $web_browser is a command plus some arguments
7197-
if {[catch {eval exec $web_browser [list $url] &} err]} {
7205+
# Use concat here in case $web_browser is a command plus some arguments
7206+
if {[catch {safe_exec_redirect [concat $web_browser [list $url]] [list &]} err]} {
71987207
error_popup "[mc "Error starting web browser:"] $err"
71997208
}
72007209
}
@@ -9207,8 +9216,8 @@ proc diffcommits {a b} {
92079216
set fna [file join $tmpdir "commit-[string range $a 0 7]"]
92089217
set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
92099218
if {[catch {
9210-
exec git diff-tree -p --pretty $a >$fna
9211-
exec git diff-tree -p --pretty $b >$fnb
9219+
safe_exec_redirect [list git diff-tree -p --pretty $a] [list >$fna]
9220+
safe_exec_redirect [list git diff-tree -p --pretty $b] [list >$fnb]
92129221
} err]} {
92139222
error_popup [mc "Error writing commit to file: %s" $err]
92149223
return
@@ -9730,7 +9739,7 @@ proc exec_citool {tool_args {baseid {}}} {
97309739
}
97319740
}
97329741

9733-
eval exec git citool $tool_args &
9742+
safe_exec_redirect [concat git citool $tool_args] [list &]
97349743

97359744
array unset env GIT_AUTHOR_*
97369745
array set env $save_env

0 commit comments

Comments
 (0)