Commit bbc47fbb authored by Alex Brainman's avatar Alex Brainman

windows/registry: mark string end with 0 before calling Windows ExpandEnvironmentStrings

Change-Id: I02bfcdeac44167d1dbeb15bcd5c82111fba3f527
Reviewed-on: https://go-review.googlesource.com/9234Reviewed-by: 's avatarRob Pike <r@golang.org>
parent e9616980
...@@ -119,15 +119,13 @@ func ExpandString(value string) (string, error) { ...@@ -119,15 +119,13 @@ func ExpandString(value string) (string, error) {
if value == "" { if value == "" {
return "", nil return "", nil
} }
for i := 0; i < len(value); i++ { p, err := syscall.UTF16PtrFromString(value)
if value[i] == 0 { if err != nil {
return "", errors.New("string cannot have 0 inside") return "", err
}
} }
p := utf16.Encode([]rune(value))
r := make([]uint16, 100) r := make([]uint16, 100)
for { for {
n, err := expandEnvironmentStrings(&p[0], &r[0], uint32(len(r))) n, err := expandEnvironmentStrings(p, &r[0], uint32(len(r)))
if err != nil { if err != nil {
return "", err return "", err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment