daemon: When running external commands, open stdin as /dev/null
[libguestfs.git] / daemon / guestfsd.c
index e3b8883..649a630 100644 (file)
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <ctype.h>
 #include <signal.h>
 #include <printf.h>
 
+#include "c-ctype.h"
 #include "daemon.h"
 
 static char *read_cmdline (void);
@@ -654,6 +654,7 @@ commandrv (char **stdoutput, char **stderror, char const* const *argv)
 
   if (pid == 0) {              /* Child process. */
     close (0);
+    open ("/dev/null", O_RDONLY); /* Set stdin to /dev/null (ignore failure) */
     close (so_fd[0]);
     close (se_fd[0]);
     dup2 (so_fd[1], 1);
@@ -835,7 +836,7 @@ print_shell_quote (FILE *stream,
                    const struct printf_info *info ATTRIBUTE_UNUSED,
                    const void *const *args)
 {
-#define SAFE(c) (isalnum((c)) ||                                       \
+#define SAFE(c) (c_isalnum((c)) ||                                     \
                  (c) == '/' || (c) == '-' || (c) == '_' || (c) == '.')
   int i, len;
   const char *str = *((const char **) (args[0]));