]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: fix Clearenv on Plan 9
authorFazlul Shahriar <fshahriar@gmail.com>
Mon, 21 Oct 2019 16:18:27 +0000 (12:18 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 23 Oct 2019 20:13:18 +0000 (20:13 +0000)
Update #25234
Fixes #35083

Change-Id: Ida39516ab1c14a34a62c2232476a75e83f4e3f75
Reviewed-on: https://go-review.googlesource.com/c/go/+/202657
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/syscall/env_plan9.go

index 9a8a837e7d3c139fcdada50bcd36919347051155..e403a25e3148294bc35243c9eb03bfe91c2e07f0 100644 (file)
@@ -74,7 +74,21 @@ func Setenv(key, value string) error {
 }
 
 func Clearenv() {
-       RawSyscall(SYS_RFORK, RFCENVG, 0, 0)
+       // Creating a new environment group using rfork(RFCENVG) can race
+       // with access to files in /env (e.g. from Setenv or Getenv).
+       // Remove all environment variables in current environment group instead.
+       fd, err := open("/env", O_RDONLY)
+       if err != nil {
+               return
+       }
+       defer Close(fd)
+       files, err := readdirnames(fd)
+       if err != nil {
+               return
+       }
+       for _, key := range files {
+               Remove("/env/" + key)
+       }
 }
 
 func Unsetenv(key string) error {