git-gui: sanitize 'exec' arguments: background
As in the previous commits, introduce a function that sanitizes arguments intended for the process, but runs the process in the background. Convert 'exec' calls to use this new function. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Johannes Sixt committed
Apr 26, 2025 at 18:46 UTC
e883ceb1222c29f8a2325e1b4c2778b5259a3725
1 file changed
+19
-9
git-gui.sh
+19
-9
@@ -200,6 +200,14 @@ proc safe_exec {cmd} {
200
eval exec [make_arglist_safe $cmd]
201
}
202
203
+# executes one command in the background
204
+# no redirections or pipelines are possible
205
+# cmd is a list that specifies the command and its arguments
206
+# calls `exec` and returns its value
207
+proc safe_exec_bg {cmd} {
208
+ eval exec [make_arglist_safe $cmd] &
209
+}
210
+
211
proc safe_open_file {filename flags} {
212
# a file name starting with "|" would attempt to run a process
213
# but such a file name must be treated as a relative path
@@ -2202,7 +2210,7 @@ proc do_gitk {revs {is_submodule false}} {
2210
unset env(GIT_DIR)
2211
unset env(GIT_WORK_TREE)
2212
}
2205
- eval exec $cmd $revs "--" "--" &
2213
+ safe_exec_bg [concat $cmd $revs "--" "--"]
2214
2215
set env(GIT_DIR) $_gitdir
2216
set env(GIT_WORK_TREE) $_gitworktree
@@ -2239,7 +2247,7 @@ proc do_git_gui {} {
2247
set pwd [pwd]
2248
cd $current_diff_path
2249
2242
- eval exec $exe gui &
2250
+ safe_exec_bg [concat $exe gui]
2251
2252
set env(GIT_DIR) $_gitdir
2253
set env(GIT_WORK_TREE) $_gitworktree
@@ -2270,16 +2278,18 @@ proc get_explorer {} {
2278
2279
proc do_explore {} {
2280
global _gitworktree
2273
- set explorer [get_explorer]
2274
- eval exec $explorer [list [file nativename $_gitworktree]] &
2281
+ set cmd [get_explorer]
2282
+ lappend cmd [file nativename $_gitworktree]
2283
+ safe_exec_bg $cmd
2284
}
2285
2286
# Open file relative to the working tree by the default associated app.
2287
proc do_file_open {file} {
2288
global _gitworktree
2280
- set explorer [get_explorer]
2289
+ set cmd [get_explorer]
2290
set full_file_path [file join $_gitworktree $file]
2282
- exec $explorer [file nativename $full_file_path] &
2291
+ lappend cmd [file nativename $full_file_path]
2292
+ safe_exec_bg $cmd
2293
}
2294
2295
set is_quitting 0
@@ -2761,13 +2771,13 @@ if {[is_Windows]} {
2771
regsub "/mingw../libexec/git-core/git-gui$" \
2772
$normalized "/git-bash.exe" cmdLine
2773
if {$cmdLine != $normalized && [file exists $cmdLine]} {
2764
- set cmdLine [list "Git Bash" $cmdLine &]
2774
+ set cmdLine [list "Git Bash" $cmdLine]
2775
} else {
2766
- set cmdLine [list "Git Bash" bash --login -l &]
2776
+ set cmdLine [list "Git Bash" bash --login -l]
2777
}
2778
.mbar.repository add command \
2779
-label [mc "Git Bash"] \
2770
- -command {eval exec [auto_execok start] $cmdLine}
2780
+ -command {safe_exec_bg [concat [list [auto_execok start]] $cmdLine]}
2781
}
2782
2783
if {[is_Windows] || ![is_bare]} {