Clean up internal fopen uses

No need to ever not use c and e.
This commit is contained in:
Ulrich Drepper 2011-11-15 04:24:42 -05:00
parent 82af0fa8de
commit 312be3f9f5
27 changed files with 117 additions and 46 deletions

View File

@ -1,3 +1,68 @@
2011-11-15 Ulrich Drepper <drepper@gmail.com>
* time/getdate.c (__getdate_r): Set FD_CLOEXEC for given file.
* sysdeps/unix/sysv/linux/readonly-area.c (__readonly_area): Set
FD_CLOEXEC for /proc/self/maps.
* sysdeps/unix/sysv/linux/getsysstats.c (phys_pages_info): Set
FD_CLOEXEC for /proc/meminfo.
* sysdeps/posix/getaddrinfo.c (gaiconf_init): Set FD_CLOEXEC for
gai.conf.
* resolv/res_query.c (res_hostalias): Don't allow cancellation and set
FD_CLOEXEC for given file.
* resolv/res_hconf.c (do_init): Set FD_CLOEXEC for host.conf.
* resolv/gethnamaddr.c (_sethtent): Don't allow cancellation and set
FD_CLOEXEC for /etc/hosts.
(_gethtent): Likewise.
* nss/nsswitch.c (nss_parse_file): Set FD_CLOEXEC.
* nss/nss_files/files-netgrp.c (_nss_files_setnetgrent): Don't allow
cancellation and set FD_CLOEXEC for /etc/netgroup.
* nss/nss_files/files-key.c (search): Don't allow cancellation when
reading /etc/publickey.
* nss/nss_files/files-initgroups.c (_nss_files_initgroups_dyn): Don't
allow cancellation when reading /etc/group.
* nss/nss_files/files-alias.c (internal_setent): Don't allow
cancellation.
(get_next_alias): Likewise for included file. Also set FD_CLOEXEC.
* nss/nss_files/files-XXX.c (internal_setent): Don't allow cancellation
when using data file.
* nis/nss-default.c (init): Set FD_CLOEXEC for /etc/default/nss.
* nis/nis_file.c (read_nis_obj): Set FD_CLOEXEC.
(write_nis_obj): Use "c" and "e" in fopen.
* misc/mntent_r.c (__setmntent): Also append e to fopen format.
* misc/getusershell.c (initshells): Set FD_CLOEXEC for /etc/shells.
* misc/getttyent.c (setttyent): Set FD_CLOEXEC.
* misc/getpass.c (getpass): Set FD_CLOEXEC for /dev/tty.
* intl/localealias.c (read_alias_file): Set FD_CLOEXEC for
locale.alias.
* inet/ruserpass.c (ruserpass): Set FD_CLOEXEC for .netrc.
* inet/rcmd.c (iruserfopen): Set FD_CLOEXEC for hosts.equiv.
* iconv/gconv_conf.c (read_conf_file): Set FD_CLOEXEC for config file.
* hesiod/hesiod.c (parse_config_file): Prevent cancellation in config
file parsing and set FD_CLOEXEC.
2011-11-14 Ulrich Drepper <drepper@gmail.com>
* time/tzfile.c (__tzfile_read): Use "e" in fopen call.

View File

@ -278,7 +278,7 @@ parse_config_file(struct hesiod_p *ctx, const char *filename) {
/*
* Now open and parse the file...
*/
if (!(fp = fopen(filename, "r")))
if (!(fp = fopen(filename, "rce")))
return (-1);
while (fgets(buf, sizeof(buf), fp) != NULL) {
@ -482,7 +482,7 @@ __hesiod_res_get(void *context) {
void
__hesiod_res_set(void *context, struct __res_state *res,
void (*free_res)(void *)) {
void (*free_res)(void *)) {
struct hesiod_p *ctx = context;
if (ctx->res && ctx->free_res) {

View File

@ -364,7 +364,7 @@ read_conf_file (const char *filename, const char *directory, size_t dir_len,
{
/* Note the file is opened with cancellation in the I/O functions
disabled. */
FILE *fp = fopen (filename, "rc");
FILE *fp = fopen (filename, "rce");
char *line = NULL;
size_t line_len = 0;
static int modcounter;

View File

@ -149,7 +149,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
__fxprintf(NULL, "rcmd: getaddrinfo: %s\n",
gai_strerror(error));
return -1;
return -1;
}
pfd[0].events = POLLIN;
@ -488,7 +488,7 @@ iruserfopen (const char *file, uid_t okuser)
cp = _("not regular file");
else
{
res = fopen (file, "rc");
res = fopen (file, "rce");
if (!res)
cp = _("cannot open");
else if (__fxstat64 (_STAT_VER, fileno (res), &st) < 0)
@ -574,8 +574,8 @@ ruserok2_sa (ra, ralen, superuser, ruser, luser, rhost)
if (hostf != NULL)
{
isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
fclose (hostf);
isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
fclose (hostf);
}
seteuid (uid);
@ -618,7 +618,7 @@ iruserok_af (raddr, superuser, ruser, luser, af)
case AF_INET6:
ra.ss_family = AF_INET6;
memcpy (&(((struct sockaddr_in6 *)&ra)->sin6_addr), raddr,
sizeof(struct in6_addr));
sizeof(struct in6_addr));
ralen = sizeof(struct sockaddr_in6);
break;
default:
@ -778,7 +778,7 @@ __validuser2_sa(hostf, ra, ralen, luser, ruser, rhost)
while (__getline (&buf, &bufsize, hostf) > 0) {
buf[bufsize - 1] = '\0'; /* Make sure it's terminated. */
p = buf;
p = buf;
/* Skip empty or comment lines */
if (__isempty (p)) {

View File

@ -114,7 +114,7 @@ ruserpass(host, aname, apass)
buf = alloca (strlen (hdir) + 8);
__stpcpy (__stpcpy (buf, hdir), "/.netrc");
cfile = fopen(buf, "rc");
cfile = fopen(buf, "rce");
if (cfile == NULL) {
if (errno != ENOENT)
warn("%s", buf);

View File

@ -221,7 +221,7 @@ read_alias_file (fname, fname_len)
/* Note the file is opened with cancellation in the I/O functions
disabled. */
fp = fopen (full_fname, "rc");
fp = fopen (full_fname, "rce");
freea (full_fname);
if (fp == NULL)
return 0;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1992-1999,2001,2003,2004,2005 Free Software Foundation, Inc.
/* Copyright (C) 1992-1999,2001,2003-2005,2011 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
@ -57,7 +57,7 @@ getpass (prompt)
/* Try to write to and read from the terminal if we can.
If we can't open the terminal, use stderr and stdin. */
in = fopen ("/dev/tty", "w+c");
in = fopen ("/dev/tty", "w+ce");
if (in == NULL)
{
in = stdin;

View File

@ -190,7 +190,7 @@ setttyent()
if (tf) {
(void)rewind(tf);
return (1);
} else if ((tf = fopen(_PATH_TTYS, "rc"))) {
} else if ((tf = fopen(_PATH_TTYS, "rce"))) {
/* We do the locking ourselves. */
__fsetlocking (tf, FSETLOCKING_BYCALLER);
return (1);

View File

@ -104,7 +104,7 @@ initshells()
shells = NULL;
free(strings);
strings = NULL;
if ((fp = fopen(_PATH_SHELLS, "rc")) == NULL)
if ((fp = fopen(_PATH_SHELLS, "rce")) == NULL)
goto init_okshells_noclose;
if (fstat64(fileno(fp), &statb) == -1) {
init_okshells:

View File

@ -38,10 +38,10 @@ FILE *
__setmntent (const char *file, const char *mode)
{
/* Extend the mode parameter with "c" to disable cancellation in the
I/O functions. */
I/O functions and "e" to set FD_CLOEXEC. */
size_t modelen = strlen (mode);
char newmode[modelen + 2];
memcpy (mempcpy (newmode, mode, modelen), "c", 2);
char newmode[modelen + 3];
memcpy (mempcpy (newmode, mode, modelen), "ce", 3);
FILE *result = fopen (file, newmode);
if (result != NULL)

View File

@ -1,4 +1,4 @@
/* Copyright (c) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
/* Copyright (c) 1997, 1998, 1999, 2004, 2005, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@ -31,7 +31,7 @@ static void *
read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
size_t objsize)
{
FILE *in = fopen (name, "rc");
FILE *in = fopen (name, "rce");
if (in == NULL)
return NULL;
@ -59,7 +59,7 @@ read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
static bool_t
write_nis_obj (const char *name, const void *obj, iofct_t writefct)
{
FILE *out = fopen (name, "w");
FILE *out = fopen (name, "wce");
if (out == NULL)
return FALSE;

View File

@ -1,4 +1,5 @@
/* Copyright (C) 1996,2001,2004,2006,2007,2010 Free Software Foundation, Inc.
/* Copyright (C) 1996,2001,2004,2006,2007,2010,2011
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
@ -57,7 +58,7 @@ static void
init (void)
{
int saved_errno = errno;
FILE *fp = fopen (default_nss, "rc");
FILE *fp = fopen (default_nss, "rce");
if (fp != NULL)
{
char *line = NULL;

View File

@ -1,3 +1,8 @@
2011-11-15 Ulrich Drepper <drepper@gmail.com>
* pthread_getattr_np.c (pthread_getattr_np): Set FD_CLOEXEC for
/proc/self/maps.
2011-10-29 Ulrich Drepper <drepper@gmail.com>
[BZ #13358]

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
/* Copyright (C) 2002-2004, 2006, 2007, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@ -75,7 +75,7 @@ pthread_getattr_np (thread_id, attr)
/* The safest way to get the top of the stack is to read
/proc/self/maps and locate the line into which
__libc_stack_end falls. */
FILE *fp = fopen ("/proc/self/maps", "rc");
FILE *fp = fopen ("/proc/self/maps", "rce");
if (fp == NULL)
ret = errno;
/* We need the limit of the stack in any case. */
@ -164,7 +164,7 @@ pthread_getattr_np (thread_id, attr)
{
free (cpuset);
if (ret == ENOSYS)
{
{
/* There is no such functionality. */
ret = 0;
iattr->cpuset = NULL;

View File

@ -77,7 +77,7 @@ internal_setent (int stayopen)
if (stream == NULL)
{
stream = fopen (DATAFILE, "re");
stream = fopen (DATAFILE, "rce");
if (stream == NULL)
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;

View File

@ -48,7 +48,7 @@ internal_setent (void)
if (stream == NULL)
{
stream = fopen ("/etc/aliases", "re");
stream = fopen ("/etc/aliases", "rce");
if (stream == NULL)
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
@ -258,7 +258,7 @@ get_next_alias (const char *match, struct aliasent *result,
first_unused = cp;
listfile = fopen (&cp[9], "r");
listfile = fopen (&cp[9], "rce");
/* If the file does not exist we simply ignore
the statement. */
if (listfile != NULL

View File

@ -30,7 +30,7 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start,
long int *size, gid_t **groupsp, long int limit,
int *errnop)
{
FILE *stream = fopen ("/etc/group", "re");
FILE *stream = fopen ("/etc/group", "rce");
if (stream == NULL)
{
*errnop = errno;

View File

@ -33,7 +33,7 @@ extern int xdecrypt (char *, char *);
static enum nss_status
search (const char *netname, char *result, int *errnop, int secret)
{
FILE *stream = fopen (DATAFILE, "re");
FILE *stream = fopen (DATAFILE, "rce");
if (stream == NULL)
return errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;

View File

@ -1,5 +1,5 @@
/* Netgroup file parser in nss_files modules.
Copyright (C) 1996, 1997, 2000, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1996, 1997, 2000, 2004, 2005, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@ -63,7 +63,7 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result)
return NSS_STATUS_UNAVAIL;
/* Find the netgroups file and open it. */
fp = fopen (DATAFILE, "r");
fp = fopen (DATAFILE, "rce");
if (fp == NULL)
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
else

View File

@ -503,7 +503,7 @@ nss_parse_file (const char *fname)
size_t len;
/* Open the configuration file. */
fp = fopen (fname, "rc");
fp = fopen (fname, "rce");
if (fp == NULL)
return NULL;

View File

@ -585,7 +585,7 @@ gethostbyname2(name, af)
}
if (!isdigit(*cp) && *cp != '.')
break;
}
}
if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||
name[0] == ':')
for (cp = name;; ++cp) {
@ -787,7 +787,7 @@ _sethtent(f)
int f;
{
if (!hostf)
hostf = fopen(_PATH_HOSTS, "r" );
hostf = fopen(_PATH_HOSTS, "rce" );
else
rewind(hostf);
stayopen = f;
@ -810,7 +810,7 @@ _gethtent()
register char *cp, **q;
int af, len;
if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
if (!hostf && !(hostf = fopen(_PATH_HOSTS, "rce" ))) {
__set_h_errno (NETDB_INTERNAL);
return (NULL);
}

View File

@ -307,7 +307,7 @@ do_init (void)
if (hconf_name == NULL)
hconf_name = _PATH_HOSTCONF;
fp = fopen (hconf_name, "rc");
fp = fopen (hconf_name, "rce");
if (fp)
{
/* No threads using this stream. */

View File

@ -602,7 +602,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
if (statp->options & RES_NOALIASES)
return (NULL);
file = getenv("HOSTALIASES");
if (file == NULL || (fp = fopen(file, "r")) == NULL)
if (file == NULL || (fp = fopen(file, "rce")) == NULL)
return (NULL);
setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';

View File

@ -1958,7 +1958,7 @@ gaiconf_init (void)
size_t nscopelist = 0;
bool scopelist_nullbits = false;
FILE *fp = fopen (GAICONF_FNAME, "rc");
FILE *fp = fopen (GAICONF_FNAME, "rce");
if (fp != NULL)
{
struct stat64 st;

View File

@ -296,7 +296,7 @@ phys_pages_info (const char *format)
long int result = -1;
/* If we haven't found an appropriate entry return 1. */
FILE *fp = fopen ("/proc/meminfo", "rc");
FILE *fp = fopen ("/proc/meminfo", "rce");
if (fp != NULL)
{
/* No threads use this stream. */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
/* Copyright (C) 2004, 2005, 2011 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
@ -32,7 +32,7 @@ __readonly_area (const char *ptr, size_t size)
{
const void *ptr_end = ptr + size;
FILE *fp = fopen ("/proc/self/maps", "rc");
FILE *fp = fopen ("/proc/self/maps", "rce");
if (fp == NULL)
{
/* It is the system administrator's choice to not have /proc

View File

@ -1,5 +1,5 @@
/* Convert a string representation of time to a time value.
Copyright (C) 1997,1998,1999,2000,2001,2003 Free Software Foundation, Inc.
Copyright (C) 1997-2001,2003,2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
@ -44,7 +44,7 @@ static int check_mday (int year, int mon, int mday);
6 memory allication failed (not enough memory available),
7 there is no line in the template that matches the input,
8 invalid input specification Example: February 31 or a time is
specified that can not be represented in a time_t (representing
specified that can not be represented in a time_t (representing
the time in seconds since 00:00:00 UTC, January 1, 1970) */
int getdate_err;
@ -129,7 +129,7 @@ __getdate_r (const char *string, struct tm *tp)
return 2;
/* Open the template file. */
fp = fopen (datemsk, "rc");
fp = fopen (datemsk, "rce");
if (fp == NULL)
return 2;