From patchwork Thu Apr 27 18:50:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 756104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wDQyh0dmWz9s8N for ; Fri, 28 Apr 2017 04:51:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="V5ylXLdl"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=wRv2ciHWt3XT2UyNX2ODwXCDNZqSoqB/U11ZmOJlRgZkEoFZ0Zkxm qVmUlFwz25TpexsZi2jkiCbsxDtJYbL2fuAR7eUMIiCewlz+2K0YRzG/ke+a1/6G V9/45a253XyadTdA7hTi1Gvy+w9++gDmveg+Sobmib3guhQizHQawU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=jQHjd8+rZQKFw+5bkfNZDnTUBn8=; b=V5ylXLdlJsFfDTK6vdMh TfywivjTfZezPEpxzPO0zLt8EZtx1+kwO+NXX7UZM4CBnixHeZC5PTRsNDUpVY5M cXzWLslavSVm3VpXF+lDgiF6Eepesv0CntvrvizgLzIiHNaBQ095HT4W+OMwiMWF yQV/PoS6N83gIw2MXY+owl0= Received: (qmail 57574 invoked by alias); 27 Apr 2017 18:51:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57518 invoked by uid 89); 27 Apr 2017 18:51:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=3720 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lf0-f68.google.com Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Apr 2017 18:51:00 +0000 Received: by mail-lf0-f68.google.com with SMTP id 88so5009287lfr.0; Thu, 27 Apr 2017 11:51:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3KVxJBBT88GduJ2k/bupFUcwLbLMjyZjC+kHsEVwigA=; b=iZ5f+Bo2fZshmW/0wnzYEhPQuh4mIujJ7Gbq2DVRu7WezoWopNRZXPytO/TY/F1x+4 VypqvZfFf0LMklkMIsrKXHe1BGi2v27XnpiMpMCh5h1PjlE7YvXd+nrWuedHs9QG4wYF VOM+o2tSAGtj8oAfNyMI2W+0ZrvfDuLsXFfE4KI7KcyISHTgP90LDWjzUs/je6JPtOxP RIlcGqEopuvJ4YVzKCA3CTzlG62Ke8fXndJpHS4AyhASVMK97hILf88l4gVX+vKglA2N hVUgbSioTiFoGuCeurXEkk15uHNr+VDAMnw4b0Mt3/OABzXsr/zwaPuYNIVkxOV9/wEZ Gfgg== X-Gm-Message-State: AN3rC/7QN2K7stGXpSEzaUigj584CxPDKvYNISWAVcwxtkNTqSopqRUS hlz/h79OpYzavHmE X-Received: by 10.25.198.197 with SMTP id w188mr2611122lff.175.1493319060424; Thu, 27 Apr 2017 11:51:00 -0700 (PDT) Received: from dt.lan (91-159-207-203.elisa-laajakaista.fi. [91.159.207.203]) by smtp.gmail.com with ESMTPSA id r22sm602631ljd.54.2017.04.27.11.50.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 11:50:59 -0700 (PDT) From: Janne Blomqvist To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Janne Blomqvist Subject: [PATCH] Don't assume __secure_getenv is available Date: Thu, 27 Apr 2017 21:50:51 +0300 Message-Id: <1493319051-25795-1-git-send-email-blomqvist.janne@gmail.com> In-Reply-To: <20170427125804.GZ1809@tucnak> References: <20170427125804.GZ1809@tucnak> 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. Regtested on x86_64-pc-linux-gnu, Ok for trunk, 7.x when it reopens, 6, 5? 2017-04-27 Janne Blomqvist * libgfortran.h: HAVE_SECURE_GETENV: Don't check HAVE___SECURE_GETENV. * environ/runtime.c (secure_getenv): Use __secure_getenv via a weak reference. * Makefile.in: Regenerated. --- libgfortran/Makefile.in | 5 +++-- libgfortran/libgfortran.h | 4 +--- libgfortran/runtime/environ.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 05b183d..4914a6f 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -137,8 +137,9 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \ $(top_srcdir)/acinclude.m4 $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../config/no-executables.m4 \ - $(top_srcdir)/../config/math.m4 $(top_srcdir)/../libtool.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/../config/math.m4 \ + $(top_srcdir)/../config/ax_check_define.m4 \ + $(top_srcdir)/../libtool.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index cfa4fcf..9d9d117 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 bf02188..969dcdf 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_gettime"))); +#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