Skip to content

Commit 78e0ae5

Browse files
os/exec: not add a suffix to Cmd.Path
For avoid data race for cmd.Path , in CL 527820 fixed data race , but addition of suffixe as shown in #66586 was also introduced. The result of call lookExtensions is actually the name passed to os.StartProcess, But solutions at the time chose to reuse cmd.Path to represent the name passed to os.StartProcess,since this results in #66586, So use new field save call lookExtensions result. Fixes #66586 Change-Id: Ib1baa6d7803f9471af6e38bcb55f0298422e6743
1 parent 8960925 commit 78e0ae5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/os/exec/exec.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ type Cmd struct {
332332
// See https://go.dev/blog/path-security
333333
// and https://go.dev/issue/43724 for more context.
334334
lookPathErr error
335+
336+
// cacheLookExtensions cache the result of calling lookExtensions,
337+
// use it only on windows.
338+
cacheLookExtensions string
335339
}
336340

337341
// A ctxResult reports the result of watching the Context associated with a
@@ -437,9 +441,7 @@ func Command(name string, arg ...string) *Cmd {
437441
// cmd.Dir may be set after we return from this function and that may cause
438442
// the command to resolve to a different extension.
439443
lp, err := lookExtensions(name, "")
440-
if lp != "" {
441-
cmd.Path = lp
442-
}
444+
cmd.cacheLookExtensions = lp
443445
if err != nil {
444446
cmd.Err = err
445447
}
@@ -640,8 +642,8 @@ func (c *Cmd) Start() error {
640642
}
641643
return c.Err
642644
}
643-
lp := c.Path
644-
if runtime.GOOS == "windows" && !filepath.IsAbs(c.Path) {
645+
lp := c.cacheLookExtensions
646+
if lp == "" && runtime.GOOS == "windows" {
645647
// If c.Path is relative, we had to wait until now
646648
// to resolve it in case c.Dir was changed.
647649
// (If it is absolute, we already resolved its extension in Command

0 commit comments

Comments
 (0)