From d68171edce96cb59b5cb869f6a82afcc50db00be Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 28 Sep 1996 03:24:10 +0000 Subject: update from main archive 960927 Sat Sep 28 03:02:49 1996 Ulrich Drepper * dirent/Makefile (routines): Add readdir_r. * dirent/readdir_r.c: New file. Wrapper around readdir.c. * dirent/dirent.h: Add prototype for readdir_r. * misc/hsearch_r.c (ENTRY): Make field `used' of type `unsigned int' to prevent warnings. * sysdeps/unix/sysv/linux/getsysstats.c (get_proc_path): Initialize `result'. Sat Sep 28 01:16:42 1996 Ulrich Drepper * sysdeps/generic/strsep.c: Rename to __strsep and make strsep weak alias. * string/string.h: Add prototype for __strsep. * misc/mntent_r.c: Use __strsep instead of strsep to keep namespace clean. * sysdeps/stub/nanosleep.c: Rename to __libc_nanosleep and make __nanosleep and nanosleep weak aliases. * sysdeps/unix/sysv/linux/syscalls.list: Add __nanosleep as weak alias. * sysdeps/unix/sysv/linux/sleep.c: Call __nanosleep instead of nanosleep to keep namespace clean. * sysdeps/posix/ttyname.c (ttyname): Add cast to prevent warning. * sysdeps/posix/ttyname_r.c (ttyname_r): Likewise. * sysdeps/posix/getcwd.c (__getcwd): Likewise. * sysdeps/unix/nlist.c: Use ISO C definition since we don't always have prototype. * login/Makefile (headers): Add pty.h. * login/pty.h: New file. * sysdeps/generic/pty.h: Include . * login/pututline_r.c: Add cast to prevent warning. * gmon/gmon.c: Add prototype for __profile_frequency. (monstartup): Add cast to prevent warning. * sysdeps/generic/prof-freq.c: Change to use ISO C style definition. * locale/programs/ld-time.c (time_output): Write `era' information in correct order. Sat Sep 28 00:11:08 1996 Ulrich Drepper * sysdeps/unix/sysv/linux/syscalls.list: Add weak alias `adjtimex'. Set caller for mlock, mlockall, mremap, munlock, and munlockall to EXTRA. Reported by Matthias Urlichs . 1996-09-27 Paul Eggert * strftime.c (strftime): Output incomplete formats like %E at end of string. 1996-09-27 Paul Eggert * strftime.c (strftime): Add support for %EC and %Ey. Fix support for %EY. This uses the new _nl_get_era_entry function. Fri Sep 27 14:12:27 1996 Ulrich Drepper Security related patch by Elliot Lee and David Holland . * inet/rexec.c (rexec): Increase size of `num' array from 8 to 32. * inet/ruserpass.c (ruserpass): Don't allow $HOME envvar to not exist. * sysdeps/generic/getenv.c (__secure_getenv): New function. Return NULL when programs runs with SUID or SGID enabled. * sysdeps/stub/getenv.c: Make __secure_getenv an alias of getenv. * stdlib/stdlib.h: Add prototype for __secure_getenv. * locale/setlocale.c: Use __secure_getenv. * resolv/res_init.c: Likewise. * resolv/res_query.c: Likewise. * inet/ruserpass.c: Likewise. * sysdeps/posix/tempname.c: Likewise. * malloc/mtrace.c: Likewise. * catgets/catgets.c: Likewise. Make temporary file handling functions reentrant. * stdio-common/tmpnam.c: Rewrite to have own buffer to write result to. The called __stdio_gen_tempname function must be thread safe. * stdio-common/tmpnam_r.c: New file. * stdio/stdio.h: Add prototype for `tmpnam_r'. Change prototype for __stdio_gen_tempname. * stdio/libio.h: Likewise. * sysdeps/posix/tempname.c: Add new parameters and use them instead of static buffer. Don't reset `indeces' when PID changed between calls. Don't fail for long running programs when index counter once reached the limit. * sysdeps/stub/tempname.c: Likewise. * stdio-common/tempnam.c: Provide local buffer as extra argument to __stdio_gen_tempname. This makes this function reentrant. * stdio-common/tmpfile.c: Likewise. * stdio-common/temptest.c: Provide extra argument to __stdio_gen_tempname. * manual/filesys.texi: Describe tmpnam_r and add comments about reentrancy of the functions. * inet/rcmd.c: Fixed address length handling. * sysdeps/posix/mk-stdiolim.c: Count final \0 byte in L_tmpnam value. * time/strftime.c: Remove unused variables alt_digits and end_alt_digits. * sysdeps/unix/sysv/linux/sys/sysinfo.h: Correct prototype names for get_nprocs and get_nprocs_conf. * sysdeps/generic/sys/sysinfo.h: Likewise. * stdlib/test-canon.c: Finally do the right fix. * misc/Makefile: Only compile force-wrapper when compiling reentrant libc. --- sysdeps/generic/getenv.c | 23 ++++++++++---- sysdeps/generic/prof-freq.c | 2 +- sysdeps/generic/pty.c | 3 +- sysdeps/generic/strsep.c | 3 +- sysdeps/generic/sys/sysinfo.h | 8 ++--- sysdeps/posix/getcwd.c | 4 +-- sysdeps/posix/mk-stdiolim.c | 8 ++--- sysdeps/posix/tempname.c | 58 +++++++++++++++++++++++------------ sysdeps/posix/ttyname.c | 2 +- sysdeps/posix/ttyname_r.c | 2 +- sysdeps/stub/getenv.c | 1 + sysdeps/stub/nanosleep.c | 6 +++- sysdeps/stub/tempname.c | 4 ++- sysdeps/unix/nlist.c | 4 +-- sysdeps/unix/sysv/linux/getsysstats.c | 9 ++---- sysdeps/unix/sysv/linux/sleep.c | 2 +- sysdeps/unix/sysv/linux/sys/sysinfo.h | 8 ++--- sysdeps/unix/sysv/linux/syscalls.list | 14 ++++----- 18 files changed, 98 insertions(+), 63 deletions(-) (limited to 'sysdeps') diff --git a/sysdeps/generic/getenv.c b/sysdeps/generic/getenv.c index d4099a9733..daf292743a 100644 --- a/sysdeps/generic/getenv.c +++ b/sysdeps/generic/getenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1994, 1996 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 +16,6 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include #include #include @@ -28,17 +27,29 @@ Cambridge, MA 02139, USA. */ /* Return the value of the environment variable NAME. */ char * -DEFUN(getenv, (name), register CONST char *name) +getenv (name) + const char *name; { - register CONST size_t len = strlen(name); - register char **ep; + const size_t len = strlen (name); + char **ep; if (__environ == NULL) return NULL; for (ep = __environ; *ep != NULL; ++ep) - if (!strncmp(*ep, name, len) && (*ep)[len] == '=') + if (!strncmp (*ep, name, len) && (*ep)[len] == '=') return &(*ep)[len + 1]; return NULL; } + + +/* Some programs and especially the libc itself have to be careful + what values to accept from the environment. This special version + checks for SUID or SGID first before doing any work. */ +char * +__secure_getenv (name) + const char *name; +{ + return __libc_enable_secure ? NULL : getenv (name); +} diff --git a/sysdeps/generic/prof-freq.c b/sysdeps/generic/prof-freq.c index 4ad42124e8..ff085145b5 100644 --- a/sysdeps/generic/prof-freq.c +++ b/sysdeps/generic/prof-freq.c @@ -37,7 +37,7 @@ #include int -__profile_frequency () +__profile_frequency (void) { /* * Discover the tick frequency of the machine if something goes wrong, diff --git a/sysdeps/generic/pty.c b/sysdeps/generic/pty.c index dda2125836..6995417d3a 100644 --- a/sysdeps/generic/pty.c +++ b/sysdeps/generic/pty.c @@ -46,6 +46,7 @@ static char sccsid[] = "@(#)pty.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include int openpty(amaster, aslave, name, termp, winp) @@ -105,7 +106,7 @@ forkpty(amaster, name, termp, winp) struct termios *termp; struct winsize *winp; { - extern int login_tty(); + extern int login_tty __P ((int fd)); int master, slave, pid; if (openpty(&master, &slave, name, termp, winp) == -1) diff --git a/sysdeps/generic/strsep.c b/sysdeps/generic/strsep.c index 6fbcb084a6..15c5891044 100644 --- a/sysdeps/generic/strsep.c +++ b/sysdeps/generic/strsep.c @@ -19,7 +19,7 @@ Boston, MA 02111-1307, USA. */ #include char * -strsep (char **stringp, const char *delim) +__strsep (char **stringp, const char *delim) { char *begin, *end; @@ -41,3 +41,4 @@ strsep (char **stringp, const char *delim) return begin; } +weak_alias (__strsep, strsep) diff --git a/sysdeps/generic/sys/sysinfo.h b/sysdeps/generic/sys/sysinfo.h index e9f667499e..f68fcc032c 100644 --- a/sysdeps/generic/sys/sysinfo.h +++ b/sysdeps/generic/sys/sysinfo.h @@ -22,12 +22,12 @@ Boston, MA 02111-1307, USA. */ #include /* Return number of configured processors. */ -extern int __get_nproc_conf __P ((void)); -extern int get_nproc_conf __P ((void)); +extern int __get_nprocs_conf __P ((void)); +extern int get_nprocs_conf __P ((void)); /* Return number of available processors. */ -extern int __get_nproc __P ((void)); -extern int get_nproc __P ((void)); +extern int __get_nprocs __P ((void)); +extern int get_nprocs __P ((void)); /* Return number of physical pages of memory in the system. */ diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c index a9536b95cf..825599f370 100644 --- a/sysdeps/posix/getcwd.c +++ b/sysdeps/posix/getcwd.c @@ -298,7 +298,7 @@ __getcwd (buf, size) (d->d_name[1] == '\0' || (d->d_name[1] == '.' && d->d_name[2] == '\0'))) continue; - if (mount_point || d->d_ino == thisino) + if (mount_point || (ino_t) d->d_ino == thisino) { char name[dotlist + dotsize - dotp + 1 + _D_ALLOC_NAMLEN (d)]; memcpy (name, dotp, dotlist + dotsize - dotp); @@ -326,7 +326,7 @@ __getcwd (buf, size) { size_t namlen = _D_EXACT_NAMLEN (d); - if (pathp - path < namlen) + if ((size_t) (pathp - path) < namlen) { if (buf != NULL) { diff --git a/sysdeps/posix/mk-stdiolim.c b/sysdeps/posix/mk-stdiolim.c index da78a98394..5df460e89a 100644 --- a/sysdeps/posix/mk-stdiolim.c +++ b/sysdeps/posix/mk-stdiolim.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1993, 1996 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 @@ -23,7 +23,7 @@ main() { /* These values correspond to the code in sysdeps/posix/tempname.c. Change the values here if you change that code. */ - printf("#define L_tmpnam %u\n", sizeof("/usr/tmp/") + 8); + printf("#define L_tmpnam %u\n", sizeof("/usr/tmp/") + 9); printf("#define TMP_MAX %u\n", 62 * 62 * 62); puts ("#ifdef __USE_POSIX"); @@ -36,7 +36,7 @@ main() is the case in the Hurd). ANSI still requires that FOPEN_MAX and FILENAME_MAX be defined, however. */ - printf("#define FOPEN_MAX %u\n", + printf("#define FOPEN_MAX %u\n", #ifdef OPEN_MAX OPEN_MAX @@ -51,7 +51,7 @@ main() ); - printf("#define FILENAME_MAX %u\n", + printf("#define FILENAME_MAX %u\n", #ifdef PATH_MAX PATH_MAX #else diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 6fd698e2b8..d58024fe7e 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -81,21 +81,24 @@ static const char letters[] = existing file will be returned. When the cycle reaches its end (12345ZZZ), NULL is returned. */ char * -__stdio_gen_tempname (const char *dir, const char *pfx, int dir_search, - size_t *lenptr, FILE **streamptr) +__stdio_gen_tempname (char *buf, size_t bufsize, const char *dir, + const char *pfx, int dir_search, size_t *lenptr, + FILE **streamptr) { int saverrno = errno; static const char tmpdir[] = P_tmpdir; static size_t indices[2]; size_t *idx; - static char buf[FILENAME_MAX]; +#if 0 static pid_t oldpid = (pid_t) 0; +#endif pid_t pid = __getpid(); register size_t len, plen, dlen; + int wrapped; if (dir_search) { - register const char *d = getenv ("TMPDIR"); + register const char *d = __secure_getenv ("TMPDIR"); if (d != NULL && !diraccess (d)) d = NULL; if (d == NULL && dir != NULL && diraccess (dir)) @@ -133,34 +136,51 @@ __stdio_gen_tempname (const char *dir, const char *pfx, int dir_search, dir = tmpdir; idx = &indices[(plen == 0 && dir == tmpdir) ? 1 : 0]; +#if 0 + /* XXX Is this ever useful??? At least when using a thread package + which uses different PIDs for the threads it is not helpful. */ if (pid != oldpid) { oldpid = pid; indices[0] = indices[1] = 0; } +#endif + wrapped = 0; /* We have not yet wrapped around the index counter. */ len = dlen + 1 + plen + 5 + 3; - while (*idx < ((sizeof (letters) - 1) * (sizeof (letters) - 1) * - (sizeof (letters) - 1))) + while (1) { - const size_t i = (*idx)++; + const size_t i; + + if (*idx >= ((sizeof (letters) - 1) * (sizeof (letters) - 1) * + (sizeof (letters) - 1))) + { + if (wrapped) + /* We really wrapped around this call. Can't believe it + but nevertheless stop the endless loop. */ + break; + + indices[0] = indices[1] = 0; + wrapped = 1; + } + + i = (*idx)++; /* Construct a file name and see if it already exists. We use a single counter in *IDX to cycle each of three character positions through each of 62 possible letters. */ - if (sizeof (buf) < len || - sprintf (buf, "%.*s/%.*s%.5d%c%c%c", - (int) dlen, dir, (int) plen, - pfx, pid % 100000, - letters[i % (sizeof (letters) - 1)], - letters[(i / (sizeof (letters) - 1)) - % (sizeof (letters) - 1)], - letters[(i / ((sizeof (letters) - 1) * - (sizeof (letters) - 1))) - % (sizeof (letters) - 1)] - ) != (int) len) + if (__snprintf (buf, bufsize, "%.*s/%.*s%.5d%c%c%c", + (int) dlen, dir, (int) plen, + pfx, pid % 100000, + letters[i % (sizeof (letters) - 1)], + letters[(i / (sizeof (letters) - 1)) + % (sizeof (letters) - 1)], + letters[(i / ((sizeof (letters) - 1) * + (sizeof (letters) - 1))) + % (sizeof (letters) - 1)] + ) != (int) len) return NULL; if (streamptr != NULL) @@ -176,7 +196,7 @@ __stdio_gen_tempname (const char *dir, const char *pfx, int dir_search, struct _IO_FILE_plus *fp; fp = (struct _IO_FILE_plus *) - malloc(sizeof (struct _IO_FILE_plus)); + malloc (sizeof (struct _IO_FILE_plus)); if (fp == NULL) { /* We lost trying to create a stream (out of memory?). diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c index be82827d00..9668117b47 100644 --- a/sysdeps/posix/ttyname.c +++ b/sysdeps/posix/ttyname.c @@ -57,7 +57,7 @@ ttyname (fd) return NULL; while ((d = readdir (dirstream)) != NULL) - if (d->d_fileno == myino) + if ((ino_t) d->d_fileno == myino) { size_t dlen = _D_ALLOC_NAMLEN (d); if (sizeof (dev) + dlen > namelen) diff --git a/sysdeps/posix/ttyname_r.c b/sysdeps/posix/ttyname_r.c index 1fb4b047d4..d7f6026d8a 100644 --- a/sysdeps/posix/ttyname_r.c +++ b/sysdeps/posix/ttyname_r.c @@ -72,7 +72,7 @@ __ttyname_r (fd, buf, buflen) buflen -= sizeof (dev); while ((d = readdir (dirstream)) != NULL) - if (d->d_fileno == myino) + if ((ino_t) d->d_fileno == myino) { char *cp; diff --git a/sysdeps/stub/getenv.c b/sysdeps/stub/getenv.c index fab9f08c75..f12964ed70 100644 --- a/sysdeps/stub/getenv.c +++ b/sysdeps/stub/getenv.c @@ -27,6 +27,7 @@ getenv (name) __set_errno (ENOSYS); return NULL; } +strong_alias (getenv, __secure_getenv) stub_warning (getenv) diff --git a/sysdeps/stub/nanosleep.c b/sysdeps/stub/nanosleep.c index 0995bb9654..bdc9d28f2d 100644 --- a/sysdeps/stub/nanosleep.c +++ b/sysdeps/stub/nanosleep.c @@ -22,9 +22,13 @@ Boston, MA 02111-1307, USA. */ /* Pause execution for a number of nanoseconds. */ int -nanosleep (const struct timespec *requested_time, struct timespec *remaining) +__libc_nanosleep (const struct timespec *requested_time, + struct timespec *remaining) { __set_errno (ENOSYS); return -1; } stub_warning (nanosleep) + +weak_alias (__libc_nanosleep, __nanosleep) +weak_alias (__libc_nanosleep, nanosleep) diff --git a/sysdeps/stub/tempname.c b/sysdeps/stub/tempname.c index 939c70fb0d..e38345721e 100644 --- a/sysdeps/stub/tempname.c +++ b/sysdeps/stub/tempname.c @@ -26,7 +26,9 @@ Cambridge, MA 02139, USA. */ Return the generated filename or NULL if one could not be generated, putting the length of the string in *LENPTR. */ char * -__stdio_gen_tempname (dir, pfx, dir_search, lenptr) +__stdio_gen_tempname (buf, bufsize, dir, pfx, dir_search, lenptr) + char *buf; + size_t bufsize; const char *dir; const char *pfx; int dir_search; diff --git a/sysdeps/unix/nlist.c b/sysdeps/unix/nlist.c index b40aedbc82..ffdd21d796 100644 --- a/sysdeps/unix/nlist.c +++ b/sysdeps/unix/nlist.c @@ -26,9 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ which is terminated by an element with a NULL `n_un.n_name' member, and fill in the elements of NL. */ int -nlist (file, nl) - const char *file; - struct nlist *nl; +nlist (const char *file, struct nlist *nl) { FILE *f; struct exec header; diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index c4c6fd78f6..349da98e90 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -33,14 +33,11 @@ get_proc_path (char *buffer, size_t bufsize) FILE *fp; struct mntent mount_point; struct mntent *entry; - char *result; + char *result = NULL; /* First find the mount point of the proc filesystem. */ fp = __setmntent (_PATH_MNTTAB, "r"); - if (fp == NULL) - /* Cannot find mount table file. */ - result = NULL; - else + if (fp != NULL) { while ((entry = __getmntent_r (fp, &mount_point, buffer, bufsize)) != NULL) @@ -108,7 +105,7 @@ weak_alias (__get_nprocs, get_nprocs) /* As far as I know Linux has no separate numbers for configured and available processors. So make the `get_nprocs_conf' function an - prototype. */ + alias. */ strong_alias (__get_nprocs, __get_nprocs_conf) weak_alias (__get_nprocs, get_nprocs_conf) diff --git a/sysdeps/unix/sysv/linux/sleep.c b/sysdeps/unix/sysv/linux/sleep.c index 1094df5129..a4cf47bb0b 100644 --- a/sysdeps/unix/sysv/linux/sleep.c +++ b/sysdeps/unix/sysv/linux/sleep.c @@ -26,7 +26,7 @@ sleep (unsigned int seconds) struct timespec ts = { tv_sec: (long int) seconds, tv_nsec: 0 }; unsigned int result; - if (nanosleep (&ts, &ts) == 0) + if (__nanosleep (&ts, &ts) == 0) result = 0; else /* Round remaining time. */ diff --git a/sysdeps/unix/sysv/linux/sys/sysinfo.h b/sysdeps/unix/sysv/linux/sys/sysinfo.h index 1fabb06392..fbdb1def2b 100644 --- a/sysdeps/unix/sysv/linux/sys/sysinfo.h +++ b/sysdeps/unix/sysv/linux/sys/sysinfo.h @@ -29,12 +29,12 @@ extern int sysinfo __P ((struct sysinfo *__info)); /* Return number of configured processors. */ -extern int __get_nproc_conf __P ((void)); -extern int get_nproc_conf __P ((void)); +extern int __get_nprocs_conf __P ((void)); +extern int get_nprocs_conf __P ((void)); /* Return number of available processors. */ -extern int __get_nproc __P ((void)); -extern int get_nproc __P ((void)); +extern int __get_nprocs __P ((void)); +extern int get_nprocs __P ((void)); /* Return number of physical pages of memory in the system. */ diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index 3601b5f357..f831b41072 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -1,6 +1,6 @@ # File name Caller Syscall name # args Strong name Weak names -adjtimex adjtime adjtimex 1 __adjtimex +adjtimex adjtime adjtimex 1 __adjtimex adjtimex bdflush EXTRA bdflush 2 bdflush create_module EXTRA create_module 3 create_module delete_module EXTRA delete_module 3 delete_module @@ -20,13 +20,13 @@ iopl - iopl 1 iopl ipc msgget ipc 5 __ipc klogctl EXTRA syslog 3 klogctl llseek EXTRA _llseek 5 llseek -mlock - mlock 2 __mlock mlock -mlockall - mlockall 1 __mlockall mlockall +mlock EXTRA mlock 2 __mlock mlock +mlockall EXTRA mlockall 1 __mlockall mlockall mount EXTRA mount 5 __mount mount -mremap - mremap 4 __mremap mremap -munlock - munlock 2 __munlock munlock -munlockall - munlockall 0 __munlockall munlockall -nanosleep - nanosleep 2 __libc_nanosleep nanosleep +mremap EXTRA mremap 4 __mremap mremap +munlock EXTRA munlock 2 __munlock munlock +munlockall EXTRA munlockall 0 __munlockall munlockall +nanosleep - nanosleep 2 __libc_nanosleep __nanosleep nanosleep pause - pause 0 __libc_pause pause personality init-first personality 1 __personality personality pipe - pipe 1 __pipe pipe -- cgit 1.4.1