From 316ca440b070114ba877455c3dbbcdc1b20e4f33 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 26 Sep 2000 07:56:19 +0000 Subject: Update. * misc/daemon.c (daemon): Fail if !noclose and we cannot open the real /dev/null device. * sysdeps/generic/check_fds.c: Include device-nrs.h. * sysdeps/generic/device-nrs.h: New file. * sysdeps/unix/sysv/linux/device-nrs.h: New file. * misc/Makefile (distribute): Add device-nrs.h. * posix/wordexp.c (exec_comm_child): Likewise. * locale/nl_langinfo.c: Allow use of file for __nl_langinfo_l definition. --- posix/wordexp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'posix') diff --git a/posix/wordexp.c b/posix/wordexp.c index 739df21..4bd84dd 100644 --- a/posix/wordexp.c +++ b/posix/wordexp.c @@ -44,6 +44,9 @@ /* #define NDEBUG 1 */ #include +/* Get some device information. */ +#include + /* * This is a recursive-descent-style word expansion routine. */ @@ -840,6 +843,7 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec) /* Redirect stderr to /dev/null if we have to. */ if (showerr == 0) { + struct stat64 st; int fd; __close (2); fd = __open (_PATH_DEVNULL, O_WRONLY); @@ -848,6 +852,18 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec) __dup2 (fd, 2); __close (fd); } + /* Be paranoid. Check that we actually opened the /dev/null + device. */ + if (__builtin_expect (__fxstat64 (_STAT_VER, 2, &st), 0) != 0 + || __builtin_expect (S_ISCHR (st.st_mode), 1) == 0 +#if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR + || st.st_rdev != makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR) +#endif + ) + /* It's not the /dev/null device. Stop right here. The + problem is: how do we stop? We use _exit() with an + hopefully unusual exit code. */ + _exit (90); } /* Make sure the subshell doesn't field-split on our behalf. */ -- cgit v1.1