mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
windows: fix race when allocating buffer for some windows syscalls
From main repo: https://go-review.googlesource.com/#/c/4940 Change-Id: I56fe7f6aedc0fd350abb94299ad500fcb80c049a Reviewed-on: https://go-review.googlesource.com/8604 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
+9
-11
@@ -16,19 +16,17 @@ func Getenv(key string) (value string, found bool) {
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
b := make([]uint16, 100)
|
||||
n, e := GetEnvironmentVariable(keyp, &b[0], uint32(len(b)))
|
||||
if n == 0 && e == ERROR_ENVVAR_NOT_FOUND {
|
||||
return "", false
|
||||
}
|
||||
if n > uint32(len(b)) {
|
||||
b = make([]uint16, n)
|
||||
n, e = GetEnvironmentVariable(keyp, &b[0], uint32(len(b)))
|
||||
if n > uint32(len(b)) {
|
||||
n = 0
|
||||
n := uint32(100)
|
||||
for {
|
||||
b := make([]uint16, n)
|
||||
n, err = GetEnvironmentVariable(keyp, &b[0], uint32(len(b)))
|
||||
if n == 0 && err == ERROR_ENVVAR_NOT_FOUND {
|
||||
return "", false
|
||||
}
|
||||
if n <= uint32(len(b)) {
|
||||
return string(utf16.Decode(b[:n])), true
|
||||
}
|
||||
}
|
||||
return string(utf16.Decode(b[0:n])), true
|
||||
}
|
||||
|
||||
func Setenv(key, value string) error {
|
||||
|
||||
Reference in New Issue
Block a user