From 2364a5e8fdcfea4b60a58838bcdf0a007a62bf15 Mon Sep 17 00:00:00 2001 From: Olivier Wulveryck Date: Wed, 19 Aug 2020 21:14:08 +0200 Subject: [PATCH] playground/socket: remove the os cleanup from start method of process The cleaning process happens in the end method of process, after cmd.Wait. Deleting it early while the cmd is still running is causing issues for security tools. Move the assignment of p.path along with its comment to happen earlier, after the temporary directory is created. It clarifies that the lack of call to os.RemoveAll is not a mistake. Fixes golang/go#40902 Change-Id: I0e555c58893c64a0de5880a5e12e6ff2e01b1eec Reviewed-on: https://go-review.googlesource.com/c/tools/+/249777 Run-TryBot: Dmitri Shuralyov TryBot-Result: Gobot Gobot Reviewed-by: Dmitri Shuralyov Reviewed-by: Alexander Rakoczy --- playground/socket/socket.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/playground/socket/socket.go b/playground/socket/socket.go index 953ea149fa..7101ce4e8b 100644 --- a/playground/socket/socket.go +++ b/playground/socket/socket.go @@ -359,7 +359,7 @@ func (p *process) start(body string, opt *Options) error { if err != nil { return err } - defer os.RemoveAll(path) + p.path = path // to be removed by p.end out := "prog" if runtime.GOOS == "windows" { @@ -385,7 +385,6 @@ func (p *process) start(body string, opt *Options) error { } // build x.go, creating x - p.path = path // to be removed by p.end args := []string{"go", "build", "-tags", "OMIT"} if opt != nil && opt.Race { p.out <- &Message{