From: Keith Randall Date: Thu, 23 Jan 2020 04:48:21 +0000 (-0800) Subject: runtime/cgo: fix unsetenv wrapper X-Git-Tag: go1.15beta1~1098 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4f074b58d2016eee2b63ffb668f6ed28156ecf62;p=gostls13.git runtime/cgo: fix unsetenv wrapper The wrapper takes a pointer to the argument, not the argument itself. Fixes #36705 Change-Id: I566d4457d00bf5b84e4a8315a26516975f0d7e10 Reviewed-on: https://go-review.googlesource.com/c/go/+/215942 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/cgo/gcc_setenv.c b/src/runtime/cgo/gcc_setenv.c index 88e92bfd8a..d4f798357a 100644 --- a/src/runtime/cgo/gcc_setenv.c +++ b/src/runtime/cgo/gcc_setenv.c @@ -20,9 +20,9 @@ x_cgo_setenv(char **arg) /* Stub for calling unsetenv */ void -x_cgo_unsetenv(char *arg) +x_cgo_unsetenv(char **arg) { _cgo_tsan_acquire(); - unsetenv(arg); + unsetenv(arg[0]); _cgo_tsan_release(); } diff --git a/test/fixedbugs/issue36705.go b/test/fixedbugs/issue36705.go new file mode 100644 index 0000000000..83e4136845 --- /dev/null +++ b/test/fixedbugs/issue36705.go @@ -0,0 +1,27 @@ +// +build cgo +// run + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// #include +// #include +import "C" + +import "os" + +func main() { + os.Setenv("FOO", "bar") + s := C.GoString(C.getenv(C.CString("FOO"))) + if s != "bar" { + panic("bad setenv, environment variable only has value \"" + s + "\"") + } + os.Unsetenv("FOO") + s = C.GoString(C.getenv(C.CString("FOO"))) + if s != "" { + panic("bad unsetenv, environment variable still has value \"" + s + "\"") + } +}