From 57769b5532e96a8f6b705035a39ee056a22e04c3 Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Thu, 4 Sep 2025 11:42:56 +0100 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: David du Colombier <0intro@gmail.com> --- src/os/file_plan9.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/os/file_plan9.go b/src/os/file_plan9.go index 17026409eb6..e563d123efa 100644 --- a/src/os/file_plan9.go +++ b/src/os/file_plan9.go @@ -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.