Skip to content

Commit ce9b512

Browse files
committed
runtime: copy env strings on startup
Some versions of libc, in this case Android's bionic, point environ directly at the envp memory. https://android.googlesource.com/platform/bionic/+/master/libc/bionic/libc_init_common.cpp#104 The Go runtime does something surprisingly similar, building the runtime's envs []string using gostringnocopy. Both libc and the Go runtime reusing memory interacts badly. When syscall.Setenv uses cgo to call setenv(3), C modifies the underlying memory of a Go string. This manifests on android/arm. With GOROOT=/data/local/tmp, a runtime test calls syscall.Setenv("/os"), resulting in runtime.GOROOT()=="/os\x00a/local/tmp/goroot". Avoid this by copying environment string memory into Go. Covered by runtime.TestFixedGOROOT on android/arm. Change-Id: Id0cf9553969f587addd462f2239dafca1cf371fa Reviewed-on: https://go-review.googlesource.com/7663 Reviewed-by: Keith Randall <[email protected]>
1 parent 00c73f5 commit ce9b512

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/runtime/runtime1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func goenvs_unix() {
8080

8181
envs = make([]string, n)
8282
for i := int32(0); i < n; i++ {
83-
envs[i] = gostringnocopy(argv_index(argv, argc+1+i))
83+
envs[i] = gostring(argv_index(argv, argc+1+i))
8484
}
8585
}
8686

0 commit comments

Comments
 (0)