From 93d4414035139e8f4850e7955b5edfd2d1c7f0bd Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 22 Jan 2024 12:26:36 +0100 Subject: [PATCH] posix_spawn: handle executable being a directory --- process.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/process.c b/process.c index 4a2cde53abe3ae..12d40518ec7804 100644 --- a/process.c +++ b/process.c @@ -4759,7 +4759,16 @@ rb_posix_spawn(struct rb_execarg *eargp) // posix_spawn only returns fork/vfork/clone failures. // If it failed but errno == 0, then it must be an "exec" failure. if (errno == 0) { - eaccess(abspath, X_OK); + if (!eaccess(abspath, X_OK)) { + // abspath is executable + struct stat file_stat; + if (stat(abspath, &file_stat)) { + rb_sys_fail(abspath); + } + if (S_ISDIR(file_stat.st_mode)) { + errno = EISDIR; + } + } } rb_sys_fail(abspath); }