Explorar el Código

fix(vfs): check whether a dentry is a directory before read and write

greatbridf hace 1 año
padre
commit
46dc1ed418
Se han modificado 1 ficheros con 10 adiciones y 0 borrados
  1. 10 0
      src/kernel/vfs.cpp

+ 10 - 0
src/kernel/vfs.cpp

@@ -563,6 +563,11 @@ static fs::special_node sns[8][8];
 
 size_t fs::vfs_read(fs::inode* file, char* buf, size_t buf_size, size_t offset, size_t n)
 {
+    if (S_ISDIR(file->mode)) {
+        errno = EISDIR;
+        return -1U;
+    }
+
     if (S_ISBLK(file->mode)) {
         uint32_t ret = file->fs->inode_getnode(file);
         if (ret == SN_INVALID) {
@@ -586,6 +591,11 @@ size_t fs::vfs_read(fs::inode* file, char* buf, size_t buf_size, size_t offset,
 }
 size_t fs::vfs_write(fs::inode* file, const char* buf, size_t offset, size_t n)
 {
+    if (S_ISDIR(file->mode)) {
+        errno = EISDIR;
+        return -1U;
+    }
+
     if (S_ISBLK(file->mode)) {
         uint32_t ret = file->fs->inode_getnode(file);
         if (ret == SN_INVALID) {