diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-17 11:25:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-17 11:26:20 +0100 |
commit | 5890bfe46129ddbdc350b750f9638633fd178a8e (patch) | |
tree | 64f08c39592625b23fbb09e8344327d4b41ed7b4 /conf | |
parent | updater: handle deletion more smoothly (diff) | |
download | wireguard-windows-5890bfe46129ddbdc350b750f9638633fd178a8e.tar.xz wireguard-windows-5890bfe46129ddbdc350b750f9638633fd178a8e.zip |
conf: cleanup final path buffer handling
And insist that CreateFile regard directories.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf')
-rw-r--r-- | conf/path_windows.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/conf/path_windows.go b/conf/path_windows.go index 761628fa..e02b03eb 100644 --- a/conf/path_windows.go +++ b/conf/path_windows.go @@ -8,7 +8,6 @@ package conf import ( "debug/pe" "errors" - "fmt" "os" "path/filepath" "strings" @@ -122,7 +121,7 @@ func RootDirectory(create bool) (string, error) { if err != nil && err != windows.ERROR_ALREADY_EXISTS { return "", err } - dataHandle, err = windows.CreateFile(data16, windows.READ_CONTROL|windows.WRITE_OWNER|windows.WRITE_DAC, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE, nil, windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS|windows.FILE_FLAG_OPEN_REPARSE_POINT, 0) + dataHandle, err = windows.CreateFile(data16, windows.READ_CONTROL|windows.WRITE_OWNER|windows.WRITE_DAC, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE, nil, windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS|windows.FILE_FLAG_OPEN_REPARSE_POINT|windows.FILE_ATTRIBUTE_DIRECTORY, 0) if err != nil && err != windows.ERROR_FILE_NOT_FOUND { return "", err } @@ -142,13 +141,19 @@ func RootDirectory(create bool) (string, error) { if fileInfo.FileAttributes&windows.FILE_ATTRIBUTE_REPARSE_POINT != 0 { return "", errors.New("Data directory is reparse point") } - var buf [windows.MAX_PATH * 4]uint16 - _, err = windows.GetFinalPathNameByHandle(dataHandle, &buf[0], uint32(len(buf)), 0) - if err != nil { - return "", err + buf := make([]uint16, windows.MAX_PATH+4) + for { + bufLen, err := windows.GetFinalPathNameByHandle(dataHandle, &buf[0], uint32(len(buf)), 0) + if err != nil { + return "", err + } + if bufLen < uint32(len(buf)) { + break + } + buf = make([]uint16, bufLen) } if !strings.EqualFold(`\\?\`+data, windows.UTF16ToString(buf[:])) { - return "", fmt.Errorf("Data directory jumped to unexpected location: got %q; want %q", windows.UTF16ToString(buf[:]), `\\?\`+data) + return "", errors.New("Data directory jumped to unexpected location") } err = windows.SetKernelObjectSecurity(dataHandle, windows.DACL_SECURITY_INFORMATION|windows.GROUP_SECURITY_INFORMATION|windows.OWNER_SECURITY_INFORMATION|windows.PROTECTED_DACL_SECURITY_INFORMATION, dataDirectorySd) if err != nil { |