Skip to content

Commit 8fe7861

Browse files
mark987ttaylorr
authored andcommitted
git-gui: assure PATH has only absolute elements.
Since 8f23432 (windows: ignore empty `PATH` elements, 2022-11-23), git-gui excises all empty paths from $PATH, but still allows '.' or other relative paths, which can also allow executing code from the repository. Let's remove anything except absolute elements. While here, let's remove duplicated elements, which are very common on Windows: only the first such item can do anything except waste time repeating a search. Signed-off-by: Mark Levedahl <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 676c495 commit 8fe7861

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

git-gui.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,22 @@ proc _which {what args} {
8888
set gitguidir [file dirname [info script]]
8989
regsub -all ";" $gitguidir "\\;" gitguidir
9090
set env(PATH) "$gitguidir;$env(PATH)"
91-
set _search_path [split $env(PATH) {;}]
92-
# Skip empty `PATH` elements
93-
set _search_path [lsearch -all -inline -not -exact \
94-
$_search_path ""]
91+
92+
set _path_seen [dict create]
93+
foreach p [split $env(PATH) {;}] {
94+
# Keep only absolute paths, getting rid of ., empty, etc.
95+
if {[file pathtype $p] ne {absolute}} {
96+
continue
97+
}
98+
# Keep only the first occurence of any duplicates.
99+
set norm_p [file normalize $p]
100+
if {[dict exists $_path_seen $norm_p]} {
101+
continue
102+
}
103+
dict set _path_seen $norm_p 1
104+
lappend _search_path $norm_p
105+
}
106+
unset _path_seen
95107
set _search_exe .exe
96108
} else {
97109
set _search_path [split $env(PATH) :]

0 commit comments

Comments
 (0)