Check that the path argument to OpenDir in Plan 9 is a directory,
and return error syscall.ENOTDIR if it is not.
Fixes #75196
Change-Id: I3bec6b6b40a38c21264b5d22ff3e7dfbf8c1c6d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/700855
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David du Colombier <0intro@gmail.com>
}
func openDirNolog(name string) (*File, error) {
- return openFileNolog(name, O_RDONLY, 0)
+ f, e := openFileNolog(name, O_RDONLY, 0)
+ if e != nil {
+ return nil, e
+ }
+ d, e := f.Stat()
+ if e != nil {
+ f.Close()
+ return nil, e
+ }
+ if !d.IsDir() {
+ f.Close()
+ return nil, &PathError{Op: "open", Path: name, Err: syscall.ENOTDIR}
+ }
+ return f, nil
}
// Close closes the File, rendering it unusable for I/O.