From aa67abb537f22db097db632d98212fa951bfeef0 Mon Sep 17 00:00:00 2001 From: Minep Date: Mon, 29 Apr 2024 19:51:50 +0100 Subject: [PATCH] * fix an issue that execve attempts to parse directory as elf file. --- lunaix-os/includes/lunaix/fs.h | 6 ++++++ lunaix-os/kernel/exe/exec.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lunaix-os/includes/lunaix/fs.h b/lunaix-os/includes/lunaix/fs.h index 0e2169e..0240c96 100644 --- a/lunaix-os/includes/lunaix/fs.h +++ b/lunaix-os/includes/lunaix/fs.h @@ -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(); diff --git a/lunaix-os/kernel/exe/exec.c b/lunaix-os/kernel/exe/exec.c index 6105c1c..813d5c3 100644 --- a/lunaix-os/kernel/exe/exec.c +++ b/lunaix-os/kernel/exe/exec.c @@ -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 -- 2.27.0