]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't request read access from CreateFile in Stat
authorDamien Neil <dneil@google.com>
Mon, 14 Nov 2022 18:21:51 +0000 (10:21 -0800)
committerDamien Neil <dneil@google.com>
Mon, 14 Nov 2022 19:44:44 +0000 (19:44 +0000)
CL 448897 changed os.Stat to request GENERIC_READ access when using
CreateFile to examine a file. This is unnecessary; access flags of 0
will permit examining file metadata even if the file isn't readable.
Revert to the old behavior here.

For #56217

Change-Id: I09220b3bbee304bd89f4a94ec9b0af42042b7773
Reviewed-on: https://go-review.googlesource.com/c/go/+/450296
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

src/os/stat_windows.go

index 4116e77170be36cedcc51a4595767facce0ea0ca..f8f229c709dbd90d9c8e1ecc521edd73e1d1fef6 100644 (file)
@@ -69,12 +69,8 @@ func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
        }
 
        // Finally use CreateFile.
-       h, err := syscall.CreateFile(namep,
-               syscall.GENERIC_READ,
-               syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE,
-               nil,
-               syscall.OPEN_EXISTING,
-               createFileAttrs, 0)
+       h, err := syscall.CreateFile(namep, 0, 0, nil,
+               syscall.OPEN_EXISTING, createFileAttrs, 0)
        if err != nil {
                return nil, &PathError{Op: "CreateFile", Path: name, Err: err}
        }