FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
syscall: check for invalid characters in Setenv on Unix

On POSIX, '=' in key is explicitly invalid, and '\x00' in key/value is
implicitly invalid.

Please review this at https://codereview.appspot.com/7311061/

Affected files:
A src/pkg/os/env_unix_test.go
M src/pkg/syscall/env_unix.go


Index: src/pkg/os/env_unix_test.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/env_unix_test.go
@@ -0,0 +1,30 @@
+// Copyright 2013 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.
+
+// +build darwin freebsd linux netbsd openbsd
+
+package os_test
+
+import (
+ . "os"
+ "testing"
+)
+
+var setenvEinvalTests = []struct {
+ k, v string
+}{
+ {"", ""}, // empty key
+ {"k=v", ""}, // '=' in key
+ {"\x00", ""}, // '\x00' in key
+ {"k", "\x00"}, // '\x00' in value
+}
+
+func TestSetenvUnixEinval(t *testing.T) {
+ for _, tt := range setenvEinvalTests {
+ err := Setenv(tt.k, tt.v)
+ if err == nil {
+ t.Errorf(`Setenv(%q, %q) == nil, want error`, tt.k, tt.v)
+ }
+ }
+}
Index: src/pkg/syscall/env_unix.go
===================================================================
--- a/src/pkg/syscall/env_unix.go
+++ b/src/pkg/syscall/env_unix.go
@@ -71,6 +71,16 @@
if len(key) == 0 {
return EINVAL
}
+ for _, b := range []byte(key) {
+ if b == '=' || b == 0 {
+ return EINVAL
+ }
+ }
+ for _, b := range []byte(value) {
+ if b == 0 {
+ return EINVAL
+ }
+ }

envLock.Lock()
defer envLock.Unlock()


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedFeb 9, '13 at 12:20a
activeFeb 9, '13 at 12:20a
posts1
users1
websitegolang.org

1 user in discussion

Speter Go1: 1 post

People

Translate

site design / logo © 2022 Grokbase