os: reject OpenDir of a non-directory file in Plan 9

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>
This commit is contained in:
Richard Miller 2025-09-04 11:42:56 +01:00 committed by Sean Liao
parent a6144613d3
commit 57769b5532

View file

@ -135,7 +135,20 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
}
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.