summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2017-05-19 13:25:21 +0000
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2017-05-19 13:25:21 +0000
commit8aee1d9bb4af84751adc8260c16b8a4ac0827dbb (patch)
tree7abd70258f41ca875f5067f40fc0d04d711c6a91 /libgfortran
parentfd847994d5093b888c5cc1ead8625c6c1c03501b (diff)
Don't assume __secure_getenv is available
Glibc 2.17 made __secure_getenv an officially supported function, and renamed it secure_getenv. The libgfortran configure has checked for both of these, per https://sourceware.org/glibc/wiki/Tips_and_Tricks/secure_getenv. Unfortunately, while the dynamical library (libc.so) retains the __secure_getenv symbol for backwards compatibility, the static library (libc.a) does not. This means that a libgfortran.a compiled against an older glibc will not work if one tries to link against a newer libc.a. This creates problems for providing gfortran binary distributions that work on as many target systems as possible. Thus, retain the support for __secure_getenv but call it only via a weak reference. Backported from trunk. 2017-05-19 Janne Blomqvist <jb@gcc.gnu.org> * libgfortran.h: HAVE_SECURE_GETENV: Don't check HAVE___SECURE_GETENV. * environ/runtime.c (secure_getenv): Use __secure_getenv via a weak reference. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@248273 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog8
-rw-r--r--libgfortran/libgfortran.h4
-rw-r--r--libgfortran/runtime/environ.c11
3 files changed, 20 insertions, 3 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 2541f5a824ac..6bfd3614c284 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,11 @@
+2017-05-19 Janne Blomqvist <jb@gcc.gnu.org>
+
+ Backport from trunk
+ * libgfortran.h: HAVE_SECURE_GETENV: Don't check
+ HAVE___SECURE_GETENV.
+ * environ/runtime.c (secure_getenv): Use __secure_getenv via a
+ weak reference.
+
2017-05-17 Jerry DeLisle <jvdelisle@gcc.gnu.org>
Backport from trunk
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index cfa4fcf0edc4..9d9d11728bdb 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -808,9 +808,7 @@ internal_proto(get_unformatted_convert);
/* Secure getenv() which returns NULL if running as SUID/SGID. */
#ifndef HAVE_SECURE_GETENV
-#ifdef HAVE___SECURE_GETENV
-#define secure_getenv __secure_getenv
-#elif defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
+#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
&& defined(HAVE_GETGID) && defined(HAVE_GETEGID)
#define FALLBACK_SECURE_GETENV
extern char *secure_getenv (const char *);
diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c
index bf02188edec8..f0a593e6074b 100644
--- a/libgfortran/runtime/environ.c
+++ b/libgfortran/runtime/environ.c
@@ -37,9 +37,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
provided. */
#ifdef FALLBACK_SECURE_GETENV
+
+#if SUPPORTS_WEAKREF && defined(HAVE___SECURE_GETENV)
+static char* weak_secure_getenv (const char*)
+ __attribute__((__weakref__("__secure_getenv")));
+#endif
+
char *
secure_getenv (const char *name)
{
+#if SUPPORTS_WEAKREF && defined(HAVE___SECURE_GETENV)
+ if (weak_secure_getenv)
+ return weak_secure_getenv (name);
+#endif
+
if ((getuid () == geteuid ()) && (getgid () == getegid ()))
return getenv (name);
else