diff --git a/ChangeLog b/ChangeLog index 574845e904..4c14c1d5a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2000-09-26 Ulrich Drepper + * 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. + * sysdeps/unix/sysv/linux/gethostid.c (sethostid): Use O_TRUNC to remove possible garbage at the end of the file. @@ -10,15 +18,17 @@ * stdio-common/tempnam.c: Warn about insecure tempnam. * misc/mktemp.c: Warn about insecure mktemp. - * sysdeps/unix/sysv/linux/check_fds.c: New file. * sysdeps/generic/check_fds.c: Check that file opened is really /dev/null. + * posix/wordexp.c (exec_comm_child): Likewise. * elf/rtld.c (process_envvars): Open debug output file with O_NOFOLLOW. * locale/Makefile (routines): Add nl_langinfo_l. * locale/Versions [libc] (GLIBC_2.2): Add __nl_langinfo_l. * locale/nl_langinfo_l.c: New file. + * locale/nl_langinfo.c: Allow use of file for __nl_langinfo_l + definition. 2000-09-23 Bruno Haible diff --git a/locale/nl_langinfo.c b/locale/nl_langinfo.c index 5347d79beb..7d8c9ab586 100644 --- a/locale/nl_langinfo.c +++ b/locale/nl_langinfo.c @@ -25,9 +25,16 @@ /* Return a string with the data for locale-dependent parameter ITEM. */ +#ifdef USE_IN_EXTENDED_LOCALE_MODEL +char * +__nl_langinfo_l (item, l) + nl_item item; + __locale_t l; +#else char * nl_langinfo (item) nl_item item; +#endif { int category = _NL_ITEM_CATEGORY (item); unsigned int index = _NL_ITEM_INDEX (item); @@ -37,7 +44,11 @@ nl_langinfo (item) /* Bogus category: bogus item. */ return (char *) ""; +#ifdef USE_IN_EXTENDED_LOCALE_MODEL + data = l->__locales[category]; +#else data = *_nl_current[category]; +#endif if (index >= data->nstrings) /* Bogus index for this category: bogus item. */ diff --git a/misc/Makefile b/misc/Makefile index e64451fe22..98d6942fda 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc. +# Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -59,6 +59,8 @@ routines := brk sbrk sstk ioctl \ getsysstats dirname regexp \ getloadavg +distribute := device-nrs.h + include ../Makeconfig aux := init-misc diff --git a/misc/daemon.c b/misc/daemon.c index bfa5f2edd3..dddb765daf 100644 --- a/misc/daemon.c +++ b/misc/daemon.c @@ -34,6 +34,9 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include + +#include int daemon(nochdir, noclose) @@ -57,11 +60,23 @@ daemon(nochdir, noclose) (void)__chdir("/"); if (!noclose && (fd = __open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)__dup2(fd, STDIN_FILENO); - (void)__dup2(fd, STDOUT_FILENO); - (void)__dup2(fd, STDERR_FILENO); - if (fd > 2) + struct stat64 st; + + if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &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 + ) { + (void)__dup2(fd, STDIN_FILENO); + (void)__dup2(fd, STDOUT_FILENO); + (void)__dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)__close (fd); + } else { (void)__close (fd); + return -1; + } } return (0); } diff --git a/posix/wordexp.c b/posix/wordexp.c index 739df218fb..4bd84ddb7a 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. */ diff --git a/sysdeps/generic/check_fds.c b/sysdeps/generic/check_fds.c index 9891b9c865..9e96937483 100644 --- a/sysdeps/generic/check_fds.c +++ b/sysdeps/generic/check_fds.c @@ -31,6 +31,8 @@ # define ABORT_INSTRUCTION #endif +#include + /* Should other OSes (e.g., Hurd) have different versions which can be written in a better way? */ diff --git a/sysdeps/generic/device-nrs.h b/sysdeps/generic/device-nrs.h new file mode 100644 index 0000000000..e13d35f9f2 --- /dev/null +++ b/sysdeps/generic/device-nrs.h @@ -0,0 +1,25 @@ +/* Device numbers of devices used in the implementation. Generic version. + Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _DEVICE_NRS_H +#define _DEVICE_NRS_H 1 + +/* By default we know no device numbers. */ + +#endif /* device-nrs.h */ diff --git a/sysdeps/unix/sysv/linux/check_fds.c b/sysdeps/unix/sysv/linux/device-nrs.h similarity index 79% rename from sysdeps/unix/sysv/linux/check_fds.c rename to sysdeps/unix/sysv/linux/device-nrs.h index a36a1d8f6d..6d1be9dc0f 100644 --- a/sysdeps/unix/sysv/linux/check_fds.c +++ b/sysdeps/unix/sysv/linux/device-nrs.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Device numbers of devices used in the implementation. Linux version. + Copyright (C) 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,7 +17,11 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifndef _DEVICE_NRS_H +#define _DEVICE_NRS_H 1 + +/* /dev/null is (1,3). */ #define DEV_NULL_MAJOR 1 #define DEV_NULL_MINOR 3 -#include +#endif /* device-nrs.h */