[syslinux:master] opendir: enforce the file type

syslinux-bot for H. Peter Anvin hpa at zytor.com
Wed Jun 23 12:15:02 PDT 2010


Commit-ID:  f91320f6834ad7f00ff827531780462965ac4acb
Gitweb:     http://syslinux.zytor.com/commit/f91320f6834ad7f00ff827531780462965ac4acb
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 23 Jun 2010 12:11:21 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 23 Jun 2010 12:11:21 -0700

opendir: enforce the file type

Don't allow opendir() on a non-directory.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 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 d20fc33..d071aff 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;
 }
 
 /*



More information about the Syslinux-commits mailing list