Skip to content

Commit 384b140

Browse files
mark987ttaylorr
authored andcommitted
git-gui: sanitize $PATH on all platforms
Since 8f23432 (windows: ignore empty `PATH` elements, 2022-11-23), git-gui removes empty elements from $PATH, and a prior commit made this remove all non-absolute elements from $PATH. But, this happens only on Windows. Unsafe $PATH elements in $PATH are possible on all platforms. Let's sanitize $PATH on all platforms to have consistent behavior. If a user really wants the current repository on $PATH, they can add its absolute name to $PATH. Signed-off-by: Mark Levedahl <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 8fe7861 commit 384b140

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

git-gui.sh

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,43 @@ proc is_Cygwin {} {
7777

7878
######################################################################
7979
##
80-
## PATH lookup
80+
## PATH lookup. Sanitize $PATH, assure exec/open use only that
8181

82-
set _search_path {}
83-
proc _which {what args} {
84-
global env _search_exe _search_path
82+
if {[is_Windows]} {
83+
set _path_sep {;}
84+
set _search_exe .exe
85+
} else {
86+
set _path_sep {:}
87+
set _search_exe {}
88+
}
8589

86-
if {$_search_path eq {}} {
87-
if {[is_Windows]} {
88-
set gitguidir [file dirname [info script]]
89-
regsub -all ";" $gitguidir "\\;" gitguidir
90-
set env(PATH) "$gitguidir;$env(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
107-
set _search_exe .exe
108-
} else {
109-
set _search_path [split $env(PATH) :]
110-
set _search_exe {}
111-
}
90+
if {[is_Windows]} {
91+
set gitguidir [file dirname [info script]]
92+
regsub -all ";" $gitguidir "\\;" gitguidir
93+
set env(PATH) "$gitguidir;$env(PATH)"
94+
}
95+
96+
set _search_path {}
97+
set _path_seen [dict create]
98+
foreach p [split $env(PATH) $_path_sep] {
99+
# Keep only absolute paths, getting rid of ., empty, etc.
100+
if {[file pathtype $p] ne {absolute}} {
101+
continue
112102
}
103+
# Keep only the first occurence of any duplicates.
104+
set norm_p [file normalize $p]
105+
if {[dict exists $_path_seen $norm_p]} {
106+
continue
107+
}
108+
dict set _path_seen $norm_p 1
109+
lappend _search_path $norm_p
110+
}
111+
unset _path_seen
112+
113+
set env(PATH) [join $_search_path $_path_sep]
114+
115+
proc _which {what args} {
116+
global _search_exe _search_path
113117
114118
if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
115119
set suffix {}

0 commit comments

Comments
 (0)