From 0e09ba3cd6baa291415d953f3a4725f85ed3b729 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 3de3710254f864..69cfc56ca78d4f 100644 --- a/process.c +++ b/process.c @@ -4757,7 +4757,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); }