* fix an issue that execve attempts to parse directory as elf file.
authorMinep <lunaixsky@qq.com>
Mon, 29 Apr 2024 18:51:50 +0000 (19:51 +0100)
committerMinep <lunaixsky@qq.com>
Mon, 29 Apr 2024 18:51:50 +0000 (19:51 +0100)
lunaix-os/includes/lunaix/fs.h
lunaix-os/kernel/exe/exec.c

index 0e2169e7c9f54d54acb679960659289ccf5afc62..0240c96a4ddc8348597b3096734f18477c95f7ad 100644 (file)
@@ -298,6 +298,12 @@ struct pcache_pg
     u32_t len;
 };
 
+static inline bool
+check_itype_any(struct v_inode* inode, unsigned int type_mask)
+{
+    return !!(inode->itype & type_mask) || !type_mask;
+}
+
 void
 fsm_init();
 
index 6105c1c7e2965552d4fd3035cfe5d84bf6bd1f3a..813d5c32b99ff5dd4b5ba8c5c3c56fb221fb5741 100644 (file)
@@ -201,6 +201,11 @@ exec_load_byname(struct exec_container* container, const char* filename)
         goto done;
     }
 
+    if (!check_itype_any(dnode->inode, F_FILE)) {
+        errno = EISDIR;
+        goto done;
+    }
+
     errno = exec_load(container, file);
 
     // It shouldn't matter which pid we passed. As the only reader is