Skip to content

Commit 3b67d45

Browse files
committed
gitk: use -profile tcl8 on exec calls
gitk often uses the output of Tcl's exec, and thus implicitly depends upon whatever Tcl does in transcoding stdout/stderr. A prior commit adds -profile tcl8 on [open, assuring the tcl8 behaviour is maintained. The Tcl documentation does not define any particular behavior for exec, nor is any enconding option exposed. Experiment shows that exec in Tcl 8 apparently uses the same strategy as other operations to map extended ascii characters according to ISO-8859-1. But, Tcl 9 seems to use -profile replace, meaning extended ascii characters are given the unicode "replacement" symbol �. exec is basically a shorthand for "open a pipeline, capture its stdout (and possibly stderr), trim any trailing newline, and return that." So, let's replace exec with a pipeline using [open, and where we have overridden that to use -profile tcl8. With this, the built-in exec is not called at all, so rename it out of the way. Also, remove the Windows override of exec, the replacement uses the overridden open to achieve the same PATH safety. Signed-off-by: Mark Levedahl <[email protected]>
1 parent f8ed135 commit 3b67d45

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

gitk

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,6 @@ if {[is_Windows]} {
105105
return $command_line
106106
}
107107
108-
# Override `exec` to avoid unsafe PATH lookup
109-
110-
rename exec real_exec
111-
112-
proc exec {args} {
113-
# skip options
114-
for {set i 0} {$i < [llength $args]} {incr i} {
115-
set arg [lindex $args $i]
116-
if {$arg eq "--"} {
117-
incr i
118-
break
119-
}
120-
if {[string range $arg 0 0] ne "-"} {
121-
break
122-
}
123-
}
124-
set args [sanitize_command_line $args $i]
125-
uplevel 1 real_exec $args
126-
}
127-
128108
# Override `open` to avoid unsafe PATH lookup
129109
130110
rename open real_open
@@ -141,6 +121,17 @@ if {[is_Windows]} {
141121
142122
# End of safe PATH lookup stuff
143123
124+
# exec using -profile tcl8 via open
125+
rename exec {}
126+
127+
proc exec {args} {
128+
129+
set fd [open [list | {*}$args] r]
130+
set output [string trim [read $fd]]
131+
close $fd
132+
return $output
133+
}
134+
144135
proc hasworktree {} {
145136
return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
146137
[exec git rev-parse --is-inside-git-dir] == "false"}]

0 commit comments

Comments
 (0)