mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
a6144613d3
commit
57769b5532
1 changed files with 14 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue