aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2015-03-17 10:18:30 -0400
committerDavid Crawshaw <crawshaw@golang.org>2015-03-17 17:27:42 +0000
commitce9b512cccae86cb381ef6bcf8e554a364f88aa1 (patch)
tree95c136a7a6a5e1f9233180917b0b1a371f04f49e /src/runtime
parent00c73f5c6e4b80a24eb19218c006c8a3f08e1ed8 (diff)
downloadgo-ce9b512cccae86cb381ef6bcf8e554a364f88aa1.tar.xz
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 <khr@golang.org>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/runtime1.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index ae30adb2fc..21b9b1a2b6 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -80,7 +80,7 @@ func goenvs_unix() {
envs = make([]string, n)
for i := int32(0); i < n; i++ {
- envs[i] = gostringnocopy(argv_index(argv, argc+1+i))
+ envs[i] = gostring(argv_index(argv, argc+1+i))
}
}