From f1a150ed430a21b7ca4167c67ff0a6823707fb88 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Fri, 30 Dec 2022 11:48:15 +0100 Subject: [PATCH] postfork: Also check if interpreter is a directory "#!/bin/" --- src/postfork.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/postfork.cpp b/src/postfork.cpp index 775b45a52..a2884eb33 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -462,7 +462,9 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * char interpreter_buff[128] = {}; const char *interpreter = get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff); - if (interpreter && 0 != access(interpreter, X_OK)) { + struct stat buf; + auto statret = stat(interpreter, &buf); + if (interpreter && (0 != statret || access(interpreter, X_OK))) { // Detect Windows line endings and complain specifically about them. auto len = strlen(interpreter); if (len && interpreter[len - 1] == '\r') { @@ -477,6 +479,11 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * "executable command.", actual_cmd, interpreter); } + } else if (interpreter && S_ISDIR(buf.st_mode)) { + FLOGF_SAFE(exec, + "Failed to execute process '%s': The file specified the interpreter " + "'%s', which is a directory.", + actual_cmd, interpreter); } else if (access(actual_cmd, X_OK) == 0) { FLOGF_SAFE(exec, "Failed to execute process '%s': The file exists and is executable. "