]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Clean up internal fopen uses
authorUlrich Drepper <drepper@gmail.com>
Tue, 15 Nov 2011 09:24:42 +0000 (04:24 -0500)
committerUlrich Drepper <drepper@gmail.com>
Tue, 15 Nov 2011 09:24:42 +0000 (04:24 -0500)
No need to ever not use c and e.

27 files changed:
ChangeLog
hesiod/hesiod.c
iconv/gconv_conf.c
inet/rcmd.c
inet/ruserpass.c
intl/localealias.c
misc/getpass.c
misc/getttyent.c
misc/getusershell.c
misc/mntent_r.c
nis/nis_file.c
nis/nss-default.c
nptl/ChangeLog
nptl/pthread_getattr_np.c
nss/nss_files/files-XXX.c
nss/nss_files/files-alias.c
nss/nss_files/files-initgroups.c
nss/nss_files/files-key.c
nss/nss_files/files-netgrp.c
nss/nsswitch.c
resolv/gethnamaddr.c
resolv/res_hconf.c
resolv/res_query.c
sysdeps/posix/getaddrinfo.c
sysdeps/unix/sysv/linux/getsysstats.c
sysdeps/unix/sysv/linux/readonly-area.c
time/getdate.c

index 054fbc2ac2c1219cf234c7238c3f631add84a018..139ba57532ccc0b1cfda2a447130377aa5ad20b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index b3706b506b51db9994b13a6028b9c834f57da13a..a3f22e5c8816b467fa09de84e1222293e7dcfe17 100644 (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) {
index b28cb3c9ab40a9d949fd4915a3a363f2e741accd..7b7c340e99c315a0b8601a117b6e994b502cfc86 100644 (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;
index 343e0954db2800d984d06b28d155afaad7126099..5e18b126916f7562ee9756acbb92f9d3f5b8c856 100644 (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)) {
index e5b2caf4dcedf2fa8077f45dd7e6937d446234a0..df423ba6ee8da14ed497070ed3a767acd2ef183b 100644 (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);
index 6f5fa12495c15ab395deaa51fd898f23817ec668..6cc69c84b5b8bcf1bc68866e3bf5c5aeccaf5454 100644 (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;
index 5290c3c7d3a8c3a1131452ce2ce7518b5876d806..bdfa2c807afc749e0b36f872deaa6e4922a589c2 100644 (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;
index 6d789c4e2e74110d8dff4567adf4019e52cb92cf..b1e6376fb66dc260a9c8a8d37ae86a1bc530ce5c 100644 (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);
index 0e4f79619f841484d1f947990cc538a927dca98d..2e8d97e65c77ec4a9f59ead566166d542b488ace 100644 (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:
index 0e9835c61e7886dc6dac3acbc1491a109821edb3..3b5418a193736854df9ad8a08e3380367c4fc767 100644 (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)
index 566f30c48c8cb701b9b29e7ae554499fca0ec50a..dc382424bec7a132260ff8c18405dfa122b98a0e 100644 (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;
 
index d7a3293a49dc8f7f890faf17d98f3f610d661b56..e4dc3d6af1bf02e398b4b4dd6db60170ce754b95 100644 (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;
index 1c084f7e3cc7b10bf8ea37e6f1671d3c3d31d1ed..9abaa26ba953af07014bdfe27b1fe7b76fa4ab58 100644 (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]
index 9c25caff89ad0401cf2d412fb018ccba930bf525..f03c97899ccc89e0b3905465886110078d474a73 100644 (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;
index 1a6fa0ddd535ecd6c4bfccdd356ee9d0dfb89df3..8db052903ff2082c71ab471b28e802f62e1cff26 100644 (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;
index 714299aadf34a065cf6a54d58d30c5831b3e8809..023021e6ceee3f41e03b25b5bc04e705cf3d2c03 100644 (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
index 2f88f602e772c609e5bd198d8609ae9d2d46ed78..3a3b5c1e38a4dfb7d9263b184b408f8e0eaa9fe3 100644 (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;
index fb108c8092d238c72fffabe701bee4eb75d4ffd3..cb392048255f9899f1ce0dea386448cbc4906269 100644 (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;
 
index 4b5d774fdd2d2bad3c4d62ab62b3cc24f861fb04..f70196bc7efdf062a44665e0bd6a4177050a1bdf 100644 (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
index 09fa0a6694b870839386a6f14c6d4d21a65e918a..6ac1458a62aece250adfecd901f1f50d2dad0cce 100644 (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;
 
index 5cf660a8d427319c1f17b3a9b288138d80041b3d..a8ccf1fd3aee4739d3aa9b4401a3e0f9047ce07c 100644 (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);
        }
index 7b167bb3bf8e7f9852cd3cdfe7a63e00eaa72373..6f831ec6b888e8165ced87f8a9085a07f412edee 100644 (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.  */
index 2f7cfaa4b7feffb72749ea7e3ffcdc0f9986e300..947c6513a2bd5186ddd5079c8c024df46348c2ec 100644 (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';
index 216c9cce5f931e29b6b3a5d25a3b4bb96b177ef1..1a023f91f52c21c42ad572eaaef5a304040aa2f7 100644 (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;
index 7feb7a1802f0820a84bfc2fb825a97e9922c1deb..bde3fa8999abe757ff384d7d5babbda7ee6a8678 100644 (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.  */
index 69e926a7a16d592b7cf8f21ff1cc84f9441d5b16..ce8ac94c4ccd9e52eb1e50ec32605023a1a8ab5c 100644 (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
index cbaa41dfd284c7e6f3a5d03845807507690b58b1..a95bad4c4e9b809411362d3cac17cfab710b22a0 100644 (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;