]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle non-nil-terminated environment strings on Plan 9
authorDavid du Colombier <0intro@gmail.com>
Mon, 20 Oct 2014 21:03:03 +0000 (23:03 +0200)
committerDavid du Colombier <0intro@gmail.com>
Mon, 20 Oct 2014 21:03:03 +0000 (23:03 +0200)
Russ Cox pointed out that environment strings are not
required to be nil-terminated on Plan 9.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/159130044

src/runtime/env_plan9.go

index 76e9867e030a5fea9fbdae6a56ea0dc212dfe821..e442c34835ef9c5b79d3ad9fe6fe7e514d827236 100644 (file)
@@ -30,7 +30,7 @@ func gogetenv(key string) string {
        if fd < 0 {
                return ""
        }
-       n := seek(fd, 0, 2) - 1
+       n := seek(fd, 0, 2)
        if n <= 0 {
                close(fd)
                return ""
@@ -44,6 +44,10 @@ func gogetenv(key string) string {
                return ""
        }
 
+       if p[r-1] == 0 {
+               r--
+       }
+
        var s string
        sp := (*_string)(unsafe.Pointer(&s))
        sp.str = &p[0]