summaryrefslogtreecommitdiff
path: root/core/fs
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-06-23 12:11:21 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-06-23 12:11:21 -0700
commitf91320f6834ad7f00ff827531780462965ac4acb (patch)
tree0fb656bfadbcf8c479230a86e9be6e849bd62d8d /core/fs
parente7def468fd1aee46e3c23b218b2cc12cab55c963 (diff)
downloadsyslinux-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>
Diffstat (limited to 'core/fs')
-rw-r--r--core/fs/readdir.c11
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;
}
/*