From fc097678720d7ee7148a482c20d2ffad4fd58b37 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 17 Apr 2020 21:35:02 +0100 Subject: [PATCH] Shell: Explicitly check if command is a directory This is a bit nicer than getting "Exec format error" after trying to execvp() a directory. --- Shell/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Shell/main.cpp b/Shell/main.cpp index 3e5aec114c..d6d7b12ef8 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -885,6 +885,12 @@ static int run_command(const String& cmd) if (handle_builtin(argv.size() - 1, argv.data(), retval)) return retval; + struct stat st; + if (stat(argv[0], &st) == 0 && S_ISDIR(st.st_mode)) { + fprintf(stderr, "Shell: %s: Is a directory\n", argv[0]); + return 126; + } + pid_t child = fork(); if (!child) { setpgid(0, 0);