src/os: make Environ() return a copy of the environment

Fixes #2646
This commit is contained in:
Damian Gryski
2022-02-22 11:07:05 -08:00
committed by Ayke
parent d65e3deccf
commit 08fd49fe60
+10 -1
View File
@@ -8,6 +8,7 @@ package os
import (
"internal/testlog"
"strings"
"syscall"
)
@@ -137,5 +138,13 @@ func Clearenv() {
// Environ returns a copy of strings representing the environment,
// in the form "key=value".
func Environ() []string {
return syscall.Environ()
orig := syscall.Environ()
single := strings.Join(orig, "")
env := make([]string, len(orig))
for i, v := range orig {
s := single[:len(v)]
env[i] = s
single = single[len(v):]
}
return env
}