From 84c1871d302e32ac06c906f1ae0695b4c10c207a Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 26 May 2023 17:27:37 +0200 Subject: [PATCH] libc: Check if a shell is available if system()'s command argument is NULL --- libc/src/stdlib.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libc/src/stdlib.cpp b/libc/src/stdlib.cpp index 290f66da..926a4582 100644 --- a/libc/src/stdlib.cpp +++ b/libc/src/stdlib.cpp @@ -184,11 +184,14 @@ extern "C" { if (!cmd) { - // FIXME: Check if there is a shell available in the system. - errno = ENOTSUP; - return -1; + struct stat st; + if (stat("/bin/sh", &st) < 0) return 0; + return S_ISREG(st.st_mode); } + // FIXME: During the execution of system(), SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored, in + // the process that calls system(). + pid_t child = fork(); if (child == 0) {