]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: fix unsetenv wrapper
authorKeith Randall <khr@golang.org>
Thu, 23 Jan 2020 04:48:21 +0000 (20:48 -0800)
committerKeith Randall <khr@golang.org>
Mon, 24 Feb 2020 21:32:48 +0000 (21:32 +0000)
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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/cgo/gcc_setenv.c
test/fixedbugs/issue36705.go [new file with mode: 0644]

index 88e92bfd8ae6ffcdf1bc90d0c35deab1667cf4a6..d4f798357af35c19ef3117c458106577fad486db 100644 (file)
@@ -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 (file)
index 0000000..83e4136
--- /dev/null
@@ -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 <stdlib.h>
+// #include <unistd.h>
+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 + "\"")
+       }
+}