diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 518210d0447..335942827f2 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2017-05-19 Janne Blomqvist + + 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-01-31 Steven G. Kargl PR fortran/79305 diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index 79f0d61c8e5..ef88eee4ada 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -801,9 +801,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 07c6351a8d9..c44542afa02 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