mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -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:
+5
-13
@@ -6,8 +6,6 @@
|
||||
|
||||
package windows
|
||||
|
||||
import "syscall"
|
||||
|
||||
// EscapeArg rewrites command line argument s as prescribed
|
||||
// in http://msdn.microsoft.com/en-us/library/ms880421.
|
||||
// This function returns "" (2 double quotes) if s is empty.
|
||||
@@ -85,21 +83,15 @@ func FullPath(name string) (path string, err error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
buf := make([]uint16, 100)
|
||||
n, err := GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if n > uint32(len(buf)) {
|
||||
// Windows is asking for bigger buffer.
|
||||
buf = make([]uint16, n)
|
||||
n := uint32(100)
|
||||
for {
|
||||
buf := make([]uint16, n)
|
||||
n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if n > uint32(len(buf)) {
|
||||
return "", syscall.EINVAL
|
||||
if n <= uint32(len(buf)) {
|
||||
return UTF16ToString(buf[:n]), nil
|
||||
}
|
||||
}
|
||||
return UTF16ToString(buf[:n]), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user