]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Rename __secure_getenv to secure_getenv
authorFlorian Weimer <fweimer@redhat.com>
Wed, 25 Jul 2012 17:46:22 +0000 (19:46 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 25 Jul 2012 17:46:22 +0000 (19:46 +0200)
40 files changed:
ChangeLog
NEWS
Versions.def
hesiod/hesiod.c
include/stdlib.h
inet/ruserpass.c
malloc/mtrace.c
manual/startup.texi
ports/sysdeps/unix/sysv/linux/alpha/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/arm/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/ia64/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libc.abilist
ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libc.abilist
stdlib/Makefile
stdlib/Versions
stdlib/secure-getenv.c
stdlib/stdlib.h
stdlib/tst-secure-getenv.c [new file with mode: 0644]
sysdeps/mach/hurd/tmpfile.c
sysdeps/posix/libc_fatal.c
sysdeps/posix/sysconf.c
sysdeps/posix/tempname.c
sysdeps/unix/sysv/linux/i386/nptl/libc.abilist
sysdeps/unix/sysv/linux/libc_fatal.c
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/nptl/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-64/nptl/libc.abilist
sysdeps/unix/sysv/linux/sh/nptl/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libc.abilist
sysdeps/unix/sysv/linux/x86_64/64/nptl/libc.abilist
sysdeps/unix/sysv/linux/x86_64/x32/nptl/libc.abilist

index 87552c4452980ee618fdfee9520096263cd5964f..b39a5a887f7b64e06720086964544a25173987d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,66 @@
+2012-07-25  Florian Weimer  <fweimer@redhat.com>
+
+       * Versions.def: Add GLIBC_2.17.
+
+       * stdlib/stdlib.h: Rename __secure_getenv to secure_getenv.
+       * include/stdlib.h: Rename __secure_getenv to secure_getenv.
+       Introduce __libc_secure_getenv.
+       * stdlib/Versions: Add secure_getenv and __libc_secure_getenv.
+       * stdlib/secure-getenv.c: Likewise.  Update copyright years.
+       * stdlib/tst-secure-getenv.c: New.
+       * stdlib/Makefile (tests): Add testcase.
+
+       * manual/startup.texi (Environment Access): Document
+       secure_getenv.
+
+       * hesiod/hesiod.c (hesiod_init): Rename __secure_getenv to
+       __libc_secure_getenv.
+       * inet/ruserpass.c (ruserpass): Likewise.
+       * malloc/mtrace.c (mtrace): Likewise.
+       * sysdeps/mach/hurd/tmpfile.c (__tmpfile): Likewise.
+       * sysdeps/posix/libc_fatal.c (__libc_fatal): Likewise.  Update
+       copyright years.
+       * sysdeps/posix/sysconf.c (__sysconf__check_spec): Likewise.
+       * sysdeps/posix/tempname.c: Likewise.  Evaluate
+       HAVE_SECURE_GETENV.
+       * sysdeps/unix/sysv/linux/libc_fatal.c (__libc_message): Rename
+       __secure_getenv to __libc_secure_getenv.  Update copyright years.
+
+       * sysdeps/unix/sysv/linux/i386/nptl/libc.abilist: Add secure_getenv.
+       * sysdeps/unix/sysv/linux/libc_fatal.c: Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libc.abilist:
+       Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-32/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-64/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sh/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/64/nptl/libc.abilist: Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/x32/nptl/libc.abilist: Likewise.
+       * ports/sysdeps/unix/sysv/linux/alpha/nptl/libc.abilist: Likewise.
+       * ports/sysdeps/unix/sysv/linux/arm/nptl/libc.abilist: Likewise.
+       * ports/sysdeps/unix/sysv/linux/ia64/nptl/libc.abilist: Likewise.
+       * ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libc.abilist:
+       Likewise.
+       * ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libc.abilist:
+       Likewise.
+
 2012-07-25  Joseph Myers  <joseph@codesourcery.com>
 
        * sysdeps/generic/ldsodefs.h (struct La_i86_regs): Remove.
diff --git a/NEWS b/NEWS
index 65ca380fd716549eae900eb9109c04e7e77f809f..d7084a02db320f0a382cfe866538e2fe4e9757d4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,10 @@ Version 2.17
   zEnterprise z196.
   Implemented by Andreas Krebbel.
 
+* The new function secure_getenv allows secure access to the environment,
+  returning NULL if running in a SUID/SGID process.  This function replaces
+  the internal function __secure_getenv.
+
 \f
 Version 2.16
 
index 2b44f5e0bb15732abf020ec181e9e28dda3dc616..3c9e0aedbc46a82f843dfafad652c7a917fd1616 100644 (file)
@@ -33,6 +33,7 @@ libc {
   GLIBC_2.14
   GLIBC_2.15
   GLIBC_2.16
+  GLIBC_2.17
   HURD_CTHREADS_0.3
 %ifdef EXPORT_UNWIND_FIND_FDE
   GCC_3.0
index a3f22e5c8816b467fa09de84e1222293e7dcfe17..657dabebc144db7d434fb87b8eec75d48a80be3b 100644 (file)
@@ -87,7 +87,7 @@ hesiod_init(void **context) {
        ctx->classes[0] = C_IN;
        ctx->classes[1] = C_HS;
 
-       configname = __secure_getenv("HESIOD_CONFIG");
+       configname = __libc_secure_getenv("HESIOD_CONFIG");
        if (!configname)
          configname = _PATH_HESIOD_CONF;
        if (parse_config_file(ctx, configname) < 0) {
@@ -109,7 +109,7 @@ hesiod_init(void **context) {
         * The default RHS can be overridden by an environment
         * variable.
         */
-       if ((cp = __secure_getenv("HES_DOMAIN")) != NULL) {
+       if ((cp = __libc_secure_getenv("HES_DOMAIN")) != NULL) {
                free(ctx->RHS);
                ctx->RHS = malloc(strlen(cp)+2);
                if (!ctx->RHS)
index de0b414d8600cdb018dcfe9c8793084e8ec7428c..d45b2f02de9e5d34e559d1f7ec42d94367b16839 100644 (file)
@@ -33,12 +33,13 @@ libc_hidden_proto (__strtold_l)
 libc_hidden_proto (exit)
 libc_hidden_proto (abort)
 libc_hidden_proto (getenv)
+extern __typeof (secure_getenv) __libc_secure_getenv;
+libc_hidden_proto (__libc_secure_getenv)
 libc_hidden_proto (bsearch)
 libc_hidden_proto (qsort)
 libc_hidden_proto (qsort_r)
 libc_hidden_proto (lrand48_r)
 libc_hidden_proto (wctomb)
-libc_hidden_proto (__secure_getenv)
 
 extern long int __random (void);
 extern void __srandom (unsigned int __seed);
index df423ba6ee8da14ed497070ed3a767acd2ef183b..71a734dfdac934b75d97ff53107e1e6f2320a2ef 100644 (file)
@@ -102,7 +102,7 @@ ruserpass(host, aname, apass)
        int t, usedefault = 0;
        struct stat64 stb;
 
-       hdir = __secure_getenv("HOME");
+       hdir = __libc_secure_getenv("HOME");
        if (hdir == NULL) {
                /* If we can't get HOME, fail instead of trying ".",
                   which is no improvement. This really should call
index d1049c982ca800a74e8bdac12eb3812f4de90ed6..d7a032a86a50ced64ca49712fc3a859c836dd733 100644 (file)
@@ -309,7 +309,7 @@ mtrace ()
   /* When compiling the GNU libc we use the secure getenv function
      which prevents the misuse in case of SUID or SGID enabled
      programs.  */
-  mallfile = __secure_getenv (mallenv);
+  mallfile = __libc_secure_getenv (mallenv);
 #else
   mallfile = getenv (mallenv);
 #endif
index 0420e93289c5803a67cc0a1a380837c79bc55834..d0be5e65f41891855a4e21215f361e8a7fec3c9d 100644 (file)
@@ -310,11 +310,15 @@ character, since this is assumed to terminate the string.
 
 The value of an environment variable can be accessed with the
 @code{getenv} function.  This is declared in the header file
-@file{stdlib.h}.  Modifications of enviroment variables are not
-allowed in Multi-threaded programs.  The @code{getenv} function
-can be safely used in multi-threaded programs
+@file{stdlib.h}.
 @pindex stdlib.h
 
+Libraries should use @code{secure_getenv} instead of @code{getenv}, so
+that they do not accidentally use untrusted environment variables.
+Modifications of environment variables are not allowed in
+multi-threaded programs.  The @code{getenv} and @code{secure_getenv}
+functions can be safely used in multi-threaded programs.
+
 @comment stdlib.h
 @comment ISO
 @deftypefun {char *} getenv (const char *@var{name})
@@ -326,6 +330,18 @@ environment variable @var{name} is not defined, the value is a null
 pointer.
 @end deftypefun
 
+@comment stdlib.h
+@comment GNU
+@deftypefun {char *} secure_getenv (const char *@var{name})
+This function is similar to @code{getenv}, but it returns a null
+pointer if the environment is untrusted.  This happens when the
+program file has SUID or SGID bits set.  General-purpose libraries
+should always prefer this function over @code{getenv} to avoid
+vulnerabilities if the library is referenced from a SUID/SGID program.
+
+This function is a GNU extension.
+@end deftypefun
+
 
 @comment stdlib.h
 @comment SVID
index 6d333aa522342300376653452ab2eacf7478f262..f8a3295add3d538b53a920eff6d50b40a39f968b 100644 (file)
@@ -1811,6 +1811,9 @@ GLIBC_2.16
  sys_errlist D 0x460
  sys_nerr D 0x4
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index 1f496fb61c3778451224ec829a34cadf0e8c2090..5523fdd2a3da5bb1de106533649fefe19ee8929c 100644 (file)
@@ -78,6 +78,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.4
  GLIBC_2.4 A
  _Exit F
index 6939ad73bcdcc739a5f4f316da5500c9edc21ff1..b73f5ca8f74f96644f87f7b62da4dec3709519f0 100644 (file)
@@ -78,6 +78,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index ca31ead95f4404feb53b1035eccfa2fce8f1f26f..9a924571e889f732feeba638ebad7b405e1bfddf 100644 (file)
@@ -79,6 +79,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.4
  GLIBC_2.4 A
  _Exit F
index c2706f1e1424137946d22a50c449048e30756495..fbcd20897bbab7c4b58b167f7f80aba1637969a4 100644 (file)
@@ -1767,6 +1767,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index 80f7d3321d718428c55a8570515fa06af757cdae..54e8d1a94e942af94a44c8589123714f1bd581b8 100644 (file)
@@ -2242,3 +2242,6 @@ GLIBC_2.9
  pipe2 F
 _gp_disp
  _gp_disp A
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
index 6d64e1d23831733723a308125c9d57a12dbd5994..2a0e2a2d96cc9eb3c8ffcbaedcad63e00f5a9215 100644 (file)
@@ -1390,6 +1390,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index 701152eeb501ea2d35632c5c56a4d8b0183d5b94..0e21194ac12d2edacfa9ba259d657bb172cf6444 100644 (file)
@@ -1388,6 +1388,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index 43015f4e927b06a09393bcf76511f3f6355f3bf4..11ad6a525d36467dbd5e1d0f3e42e69a2fc0800a 100644 (file)
@@ -1772,6 +1772,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index eed3b4937fcbcb9a6cf7d322fdf8970136253632..48f0c69eb87cf3489d74310c641f5f0c95aa2416 100644 (file)
@@ -2080,3 +2080,6 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
index 2dbce23ec9813833812943d4d0c4c88d44798e2f..3aa70a1004e0e4ed7020023a493de15794f1e500 100644 (file)
@@ -2080,3 +2080,6 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
index eed3b4937fcbcb9a6cf7d322fdf8970136253632..48f0c69eb87cf3489d74310c641f5f0c95aa2416 100644 (file)
@@ -2080,3 +2080,6 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
index f7811c5bbb07fb2a0e478ad2bd1ae7aaa0b3ceb4..10674f2cd773062a8eb32acf9a729f117c364ae0 100644 (file)
@@ -68,7 +68,9 @@ tests         := tst-strtol tst-strtod testmb testrand testsort testdiv   \
                   tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
                   tst-makecontext tst-strtod4 tst-strtod5 tst-qsort2       \
                   tst-makecontext2 tst-strtod6 tst-unsetenv1               \
-                  tst-makecontext3 bug-getcontext bug-fmtmsg1
+                  tst-makecontext3 bug-getcontext bug-fmtmsg1              \
+                  tst-secure-getenv
+tests-static   := tst-secure-getenv
 
 include ../Makeconfig
 
index 2aa396ecb7ec320fbd1d8425027f2ca0c0793fbc..250bd5fad7a31c2d92a947f29bc68dc7c3550f15 100644 (file)
@@ -6,7 +6,7 @@ libc {
     # functions used in inline functions or macros
     __strto*_internal;
 
-    # functions used in other libraries
+    # compatibility symbol
     __secure_getenv;
 
     # a*
@@ -103,11 +103,16 @@ libc {
   GLIBC_2.13 {
     __fentry__;
   }
+  GLIBC_2.17 {
+    secure_getenv;
+  }
   GLIBC_PRIVATE {
     # functions which have an additional interface since they are
     # are cancelable.
     __libc_system;
     # Variable which needs a dynamic symbol table entry.
     __abort_msg;
+    # Used from other libraries
+    __libc_secure_getenv;
   }
 }
index f64759f09b78d3e2efb080c1b03fd052e47b12e2..2e696e90f031ee430b95ad362e6a237eae3ee4dc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1994, 1996, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2012 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
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <shlib-compat.h>
+
 /* 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)
+__libc_secure_getenv (name)
      const char *name;
 {
   return __libc_enable_secure ? NULL : getenv (name);
 }
-libc_hidden_def (__secure_getenv)
+weak_alias (__libc_secure_getenv, secure_getenv)
+libc_hidden_weak (__libc_secure_getenv)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_16)
+compat_symbol (libc, __libc_secure_getenv, __secure_getenv, GLIBC_2_0);
+#endif
index f652eda3fed6b0191c2c15d67f81a2a92926e3d2..cf3f39ca84b3369815b1f8d8f9b0d96326a04bf8 100644 (file)
@@ -568,10 +568,12 @@ __BEGIN_NAMESPACE_STD
 extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
 __END_NAMESPACE_STD
 
+#ifdef __USE_GNU
 /* This function is similar to the above but returns NULL if the
    programs is running with SUID or SGID enabled.  */
-extern char *__secure_getenv (const char *__name)
+extern char *secure_getenv (const char *__name)
      __THROW __nonnull ((1)) __wur;
+#endif
 
 #if defined __USE_SVID || defined __USE_XOPEN
 /* The SVID says this is in <stdio.h>, but this seems a better place.  */
diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c
new file mode 100644 (file)
index 0000000..76d8de6
--- /dev/null
@@ -0,0 +1,250 @@
+/* Copyright (C) 2012 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Test that secure_getenv works by invoking the test as a SGID
+   program with a group ID from the supplementary group list.  This
+   test can fail spuriously if the user is not a member of a suitable
+   supplementary group. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+static char MAGIC_ARGUMENT[] = "run-actual-test";
+#define MAGIC_STATUS 19
+
+static const char *test_dir;
+
+/* Return a GID which is not our current GID, but is present in the
+   supplementary group list. */
+static gid_t
+choose_gid (void)
+{
+  const int count = 64;
+  gid_t groups[count];
+  int ret = getgroups (count, groups);
+  if (ret < 0)
+    {
+      perror ("getgroups");
+      exit (1);
+    }
+  gid_t current = getgid ();
+  for (int i = 0; i < ret; ++i)
+    {
+      if (groups[i] != current)
+       return groups[i];
+    }
+  return 0;
+}
+
+
+/* Copies the executable into a restricted directory, so that we can
+   safely make it SGID with the TARGET group ID.  Then runs the
+   executable. */
+static int
+run_executable_sgid (gid_t target)
+{
+  char *dirname = 0;
+  char *execname = 0;
+  int infd = -1;
+  int outfd = -1;
+  int ret = -1;
+  if (asprintf (&dirname, "%s/secure-getenv.%jd",
+               test_dir, (intmax_t) getpid ()) < 0)
+    {
+      perror ("asprintf");
+      goto err;
+    }
+  if (mkdir (dirname, 0700) < 0)
+    {
+      perror ("mkdir");
+      goto err;
+    }
+  if (asprintf (&execname, "%s/bin", dirname) < 0)
+    {
+      perror ("asprintf");
+      goto err;
+    }
+  infd = open ("/proc/self/exe", O_RDONLY);
+  if (infd < 0)
+    {
+      perror ("open");
+      goto err;
+    }
+  outfd = open (execname, O_WRONLY | O_CREAT | O_EXCL, 0700);
+  if (outfd < 0)
+    {
+      perror ("open");
+      goto err;
+    }
+  char buf[4096];
+  for (;;)
+    {
+      ssize_t rdcount = read (infd, buf, sizeof (buf));
+      if (rdcount < 0)
+       {
+         perror ("read");
+         goto err;
+       }
+      if (rdcount == 0)
+       break;
+      char *p = buf;
+      char *end = buf + rdcount;
+      while (p != end)
+       {
+         ssize_t wrcount = write (outfd, buf, end - p);
+         if (wrcount == 0)
+           errno = ENOSPC;
+         if (wrcount <= 0)
+           {
+             perror ("write");
+             goto err;
+           }
+         p += wrcount;
+       }
+    }
+  if (fchown (outfd, getuid (), target) < 0)
+    {
+      perror ("fchown");
+      goto err;
+    }
+  if (fchmod (outfd, 02750) < 0)
+    {
+      perror ("fchmod");
+      goto err;
+    }
+  if (close (outfd) < 0)
+    {
+      perror ("close");
+      goto err;
+    }
+  if (close (infd) < 0)
+    {
+      perror ("close");
+      goto err;
+    }
+
+  int kid = fork ();
+  if (kid < 0)
+    {
+      perror ("fork");
+      goto err;
+    }
+  if (kid == 0)
+    {
+      /* Child process. */
+      char *args[] = { execname, MAGIC_ARGUMENT, NULL };
+      execve (execname, args, environ);
+      perror ("execve");
+      _exit (1);
+    }
+  int status;
+  if (waitpid (kid, &status, 0) < 0)
+    {
+      perror ("waitpid");
+      goto err;
+    }
+  if (!WIFEXITED (status) || WEXITSTATUS (status) != MAGIC_STATUS)
+    {
+      fprintf (stderr, "Unexpected exit status %d from child process\n",
+              status);
+      goto err;
+    }
+  ret = 0;
+
+err:
+  if (outfd >= 0)
+    close (outfd);
+  if (infd >= 0)
+    close (infd);
+  if (execname)
+    {
+      unlink (execname);
+      free (execname);
+    }
+  if (dirname)
+    {
+      rmdir (dirname);
+      free (dirname);
+    }
+  return ret;
+}
+
+static int
+do_test (void)
+{
+  if (getenv ("PATH") == NULL)
+    {
+      fprintf (stderr, "PATH not set\n");
+      exit (1);
+    }
+  if (secure_getenv ("PATH") == NULL)
+    {
+      fprintf (stderr, "PATH not set according to secure_getenv\n");
+      exit (1);
+    }
+  if (strcmp (getenv ("PATH"), secure_getenv ("PATH")) != 0)
+    {
+      fprintf (stderr, "PATH mismatch (%s, %s)\n",
+              getenv ("PATH"), secure_getenv ("PATH"));
+      exit (1);
+    }
+
+  gid_t target = choose_gid ();
+  if (target == 0)
+    {
+      fprintf (stderr, "Could not find a suitable GID user %jd\n",
+              (intmax_t) getuid ());
+      exit (1);
+    }
+  return run_executable_sgid (target);
+}
+
+static void
+alternative_main (int argc, char **argv)
+{
+  if (argc == 2 && strcmp (argv[1], MAGIC_ARGUMENT) == 0)
+    {
+      if (getgid () == getegid ())
+       {
+         fprintf (stderr, "SGID failed: GID and EGID match (%jd)\n",
+                  (intmax_t) getgid ());
+         exit (2);
+       }
+      if (getenv ("PATH") == NULL)
+       {
+         fprintf (stderr, "PATH variable not present\n");
+         exit (3);
+       }
+      if (secure_getenv ("PATH") != NULL)
+       {
+         fprintf (stderr, "PATH variable not filtered out\n");
+         exit (4);
+       }
+      exit (MAGIC_STATUS);
+    }
+}
+
+#define PREPARE(argc, argv) alternative_main(argc, argv)
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
index 94b1380da45ed91b509250e080d40a6fa2b60213..c2aa76491619e1e59f2dd9a968021b050d92399a 100644 (file)
@@ -37,7 +37,7 @@ __tmpfile (void)
   FILE *f;
 
   /* Get a port to the directory that will contain the file.  */
-  const char *dirname = __secure_getenv ("TMPDIR") ?: P_tmpdir;
+  const char *dirname = __libc_secure_getenv ("TMPDIR") ?: P_tmpdir;
   file_t dir = __file_name_lookup (dirname, 0, 0);
   if (dir == MACH_PORT_NULL)
     return NULL;
index 62acb9bead9eed1c3a732635575ce92c105d13e2..6b741297ce81823516e2f22a0540c088d0ab2268 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 1993-1995,1997,2000,2004,2005,2009,2011
-       Free Software Foundation, Inc.
+/* Copyright (C) 1993-2012 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
@@ -61,7 +60,7 @@ __libc_message (int do_abort, const char *fmt, ...)
 
   /* Open a descriptor for /dev/tty unless the user explicitly
      requests errors on standard error.  */
-  const char *on_2 = __secure_getenv ("LIBC_FATAL_STDERR_");
+  const char *on_2 = __libc_secure_getenv ("LIBC_FATAL_STDERR_");
   if (on_2 == NULL || *on_2 == '\0')
     fd = open_not_cancel_2 (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY);
 
index 1f988d547af3f36b4e0772d1a9820bd00bcb6e09..d9b3c83ab7526f2a95453ebfc733aa13c4f72aa7 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 1991,1993,1995-1997,1999-2003,2004,2006,2009
-       Free Software Foundation, Inc.
+/* Copyright (C) 1991-2012 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
@@ -1259,7 +1258,7 @@ __sysconf_check_spec (const char *spec)
 {
   int save_errno = errno;
 
-  const char *getconf_dir = __secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR;
+  const char *getconf_dir = __libc_secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR;
   size_t getconf_dirlen = strlen (getconf_dir);
   size_t speclen = strlen (spec);
 
index a98f1d6e9b08c345b653c1906951ce6152569ff8..2f0bfef34fa31c28169c42490d18afd279436956 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2001, 2006, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2012 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
 # define __xstat64(version, path, buf) stat (path, buf)
 #endif
 
-#if ! (HAVE___SECURE_GETENV || _LIBC)
-# define __secure_getenv getenv
+#if ! (HAVE_SECURE_GETENV || _LIBC)
+# ifdef HAVE___SECURE_GETENV
+#  define __libc_secure_getenv __secure_getenv
+# else
+#  define __libc_secure_getenv getenv
+# endif
 #endif
 
 #ifdef _LIBC
@@ -168,7 +172,7 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
 
   if (try_tmpdir)
     {
-      d = __secure_getenv ("TMPDIR");
+      d = __libc_secure_getenv ("TMPDIR");
       if (d != NULL && direxists (d))
        dir = d;
       else if (dir != NULL && direxists (dir))
index d6695ebb914eb66cc8403533084a809499a1b9a3..0e8576fdd52b4db4455186d7fe47449f33af5cac 100644 (file)
@@ -1811,6 +1811,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index 58a5a7f83870c73978c774b218c789a42fcc128c..6cc96d76e98fe1917b84ef735584583c53221db7 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (C) 1993-1995,1997,2000,2002-2005,2009,2011
-   Free Software Foundation, Inc.
+/* Copyright (C) 1993-2012 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
@@ -64,7 +63,7 @@ __libc_message (int do_abort, const char *fmt, ...)
 
   /* Open a descriptor for /dev/tty unless the user explicitly
      requests errors on standard error.  */
-  const char *on_2 = __secure_getenv ("LIBC_FATAL_STDERR_");
+  const char *on_2 = __libc_secure_getenv ("LIBC_FATAL_STDERR_");
   if (on_2 == NULL || *on_2 == '\0')
     fd = open_not_cancel_2 (_PATH_TTY, O_RDWR | O_NOCTTY | O_NDELAY);
 
index 706d2a9eb8ddb76f8798aba33346b7d1fef78257..75123b9f3af56e56838d3f3479e25f6a89406a89 100644 (file)
@@ -1772,6 +1772,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index a0d362e1110ca8f00c0ca397dfcb2d5c4ce0f92d..e2484d3f22164541e251c65b16f7dbb2db2abdd4 100644 (file)
@@ -78,6 +78,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.3
  GLIBC_2.3 A
  _Exit F
index d56560112c4b966b34317c56ddec792c04b5b7f6..ff0b82f51f835173a3893745be24e35aaf54d59a 100644 (file)
@@ -1763,6 +1763,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index f161a51e291ba808a142c699d69624ef2a793580..2fb0786942c201d097f2f7604273fe3998e3c78f 100644 (file)
@@ -84,6 +84,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index c474f415c7aca90cfddcc012147d5ffc7e63a6ef..3fd150e7e57b19029bd028a40fb997ab0337deeb 100644 (file)
@@ -84,6 +84,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index 1804348cfdd4e8081c6d91182fdfdca093e67fcc..7d5a3429fdc5e7ab9e989d1701cfc089e08689fa 100644 (file)
@@ -1768,6 +1768,9 @@ GLIBC_2.16
  sys_errlist D 0x220
  sys_nerr D 0x4
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _IO_adjust_wcolumn F
index 8571fa8da92ee77006f738d41f25a75fb7d80859..6d6e57c114ba4c25d025716f87a840671654b610 100644 (file)
@@ -89,6 +89,9 @@ GLIBC_2.16
  sys_errlist D 0x440
  sys_nerr D 0x4
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2
  GLIBC_2.2 A
  _Exit F
index 2a1b8e9f93b1cca880bd3e0d9c918b3446dde24f..d6ab153e19fcc9d83998f2369f5c5edf159297e2 100644 (file)
@@ -80,6 +80,9 @@ GLIBC_2.16
  mbrtoc16 F
  mbrtoc32 F
  timespec_get F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F
 GLIBC_2.2.5
  GLIBC_2.2.5 A
  _Exit F
index 13b1d91cf434c7cd06a6fc93b96a6029eee50bc4..65bcead8bc1eb897deb2d3960536e99c48f6ec90 100644 (file)
@@ -2078,3 +2078,6 @@ GLIBC_2.16
  xencrypt F
  xprt_register F
  xprt_unregister F
+GLIBC_2.17
+ GLIBC_2.17 A
+ secure_getenv F