diff options
author | H. Peter Anvin <hpa@zytor.com> | 2010-06-23 12:11:21 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-06-23 12:11:21 -0700 |
commit | f91320f6834ad7f00ff827531780462965ac4acb (patch) | |
tree | 0fb656bfadbcf8c479230a86e9be6e849bd62d8d | |
parent | e7def468fd1aee46e3c23b218b2cc12cab55c963 (diff) | |
download | syslinux-f91320f6834ad7f00ff827531780462965ac4acb.tar.gz |
opendir: enforce the file type
Don't allow opendir() on a non-directory.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | core/fs/readdir.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/fs/readdir.c b/core/fs/readdir.c index d20fc33b..d071affd 100644 --- a/core/fs/readdir.c +++ b/core/fs/readdir.c @@ -10,13 +10,20 @@ DIR *opendir(const char *path) { int rv; + struct file *file; rv = searchdir(path); if (rv < 0) return NULL; - /* XXX: check for a directory handle here */ - return (DIR *)handle_to_file(rv); + file = handle_to_file(rv); + + if (file->inode->mode != DT_DIR) { + _close_file(file); + return NULL; + } + + return (DIR *)file; } /* |