Skip to content

Commit 57769b5

Browse files
millerresearchseankhliao
authored andcommitted
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 golang#75196 Change-Id: I3bec6b6b40a38c21264b5d22ff3e7dfbf8c1c6d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/700855 Reviewed-by: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: David du Colombier <[email protected]>
1 parent a614461 commit 57769b5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/os/file_plan9.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,20 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
135135
}
136136

137137
func openDirNolog(name string) (*File, error) {
138-
return openFileNolog(name, O_RDONLY, 0)
138+
f, e := openFileNolog(name, O_RDONLY, 0)
139+
if e != nil {
140+
return nil, e
141+
}
142+
d, e := f.Stat()
143+
if e != nil {
144+
f.Close()
145+
return nil, e
146+
}
147+
if !d.IsDir() {
148+
f.Close()
149+
return nil, &PathError{Op: "open", Path: name, Err: syscall.ENOTDIR}
150+
}
151+
return f, nil
139152
}
140153

141154
// Close closes the File, rendering it unusable for I/O.

0 commit comments

Comments
 (0)