Skip to content

Commit 08fd49f

Browse files
dgryskiaykevl
authored andcommitted
src/os: make Environ() return a copy of the environment
Fixes #2646
1 parent d65e3de commit 08fd49f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/os/env.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package os
88

99
import (
1010
"internal/testlog"
11+
"strings"
1112
"syscall"
1213
)
1314

@@ -137,5 +138,13 @@ func Clearenv() {
137138
// Environ returns a copy of strings representing the environment,
138139
// in the form "key=value".
139140
func Environ() []string {
140-
return syscall.Environ()
141+
orig := syscall.Environ()
142+
single := strings.Join(orig, "")
143+
env := make([]string, len(orig))
144+
for i, v := range orig {
145+
s := single[:len(v)]
146+
env[i] = s
147+
single = single[len(v):]
148+
}
149+
return env
141150
}

0 commit comments

Comments
 (0)