From patchwork Wed Sep 5 14:57:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 966441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485238-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WjHxsIbv"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iaCLZ/wg"; dkim-atps=neutral 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 4256Rj47yzz9s5c for ; Thu, 6 Sep 2018 01:04:17 +1000 (AEST) 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 :mime-version:content-transfer-encoding; q=dns; s=default; b=mxr GIwIyBEAgIzY20Ex03FzI9wRx4Kwr3F4MS6iezt3SngWesWSZNe37O/J1nrIyCrt M3eCVRADRW1PFoS+JQx7TzKcYpTroIKebv7G0YTP1cX6nXNUKpBLrJOulv7mCEzS 3SW7vzJ1RV6kX5hGpGgjtsrQQtC8sSlYJ9a5yamU= 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 :mime-version:content-transfer-encoding; s=default; bh=3iBdEAwsB 0uiLEQDC1ir/s+OsYs=; b=WjHxsIbvcXnCYuxQYSfzYCamvaKc4F7/swgJX+XBu 32riglT+4X81ElVXUCb6aMkPWHRD3EmAjn8171iHCXF/EGwsCe1WyhhgoIqoCbCT Qw5vvkK4Ay2Lg9uJ7KpaQOqImpdefNiYuA6fuSurCV4A8/s3oAC7sWFcgDkBwTub lI= Received: (qmail 70219 invoked by alias); 5 Sep 2018 14:58: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 69066 invoked by uid 89); 5 Sep 2018 14:57:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:l130-v6 X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 14:57:56 +0000 Received: by mail-wm0-f51.google.com with SMTP id b19-v6so8340665wme.3; Wed, 05 Sep 2018 07:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AUM8DI/ruSfmT4xZmxeo/IQP+gy6oAkG54GnFm3j3+E=; b=iaCLZ/wgoHD8RspipGPvVjcTXv/42Kp7FhOtix3uCbaUFHJeoMxrlp5hz5yVsTfsi+ UixUoIkgWrcZNPM4YgZ6868pJoflNqSpPuQ3vFNCqB6Ou/27vePwYnbKJqxD3yIfeL13 VA4uyEkYvcdSDLLWslBUMGoYFURYKx+jP85ZN8uPChI1pu5CksHSzfQMYPHq1H1mkXFf 8p1i50Xoh0z+PZheOES+ZMKdxzwV1F8wG84QeL5Xf3XQct7n7oKZ7r1e+IVQRvFNELI1 T2STV+E3VUWL2ciPt6Ri35o/PgtfL/3OxAZwYODezwg5sjFJVJ7Bf7FGtsUEilC67m0R wBlA== Received: from s46.loc (91-119-125-11.dsl.dynamic.surfer.at. [91.119.125.11]) by smtp.gmail.com with ESMTPSA id l130-v6sm3392795wmd.16.2018.09.05.07.57.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Sep 2018 07:57:51 -0700 (PDT) Received: from cow by s46.loc with local (Exim 4.91) (envelope-from ) id 1fxZFc-00008e-3m; Wed, 05 Sep 2018 14:57:48 +0000 From: Bernhard Reutner-Fischer To: fortran@gcc.gnu.org Cc: Bernhard Reutner-Fischer , gcc-patches@gcc.gnu.org Subject: [PATCH, FORTRAN 29/29] PR87103: Remove max symbol length check from gfc_new_symbol Date: Wed, 5 Sep 2018 14:57:32 +0000 Message-Id: <20180905145732.404-30-rep.dot.nop@gmail.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes From: Bernhard Reutner-Fischer gfc_match_name does check for too long names already. Since gfc_new_symbol is also called for symbols with internal names containing compiler-generated prefixes, these internal names can easily exceed the max_identifier_length mandated by the standard. gcc/fortran/ChangeLog 2018-09-04 Bernhard Reutner-Fischer PR fortran/87103 * expr.c (gfc_check_conformance): Check vsnprintf for truncation. * iresolve.c (gfc_get_string): Likewise. * symbol.c (gfc_new_symbol): Remove check for maximum symbol name length. Remove redundant 0 setting of new calloc()ed gfc_symbol. --- gcc/fortran/expr.c | 4 +++- gcc/fortran/iresolve.c | 5 ++++- gcc/fortran/symbol.c | 16 ---------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index c5bf822cd24..6b5671390ec 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3225,8 +3225,10 @@ gfc_check_conformance (gfc_expr *op1, gfc_expr *op2, const char *optype_msgid, . return true; va_start (argp, optype_msgid); - vsnprintf (buffer, 240, optype_msgid, argp); + d = vsnprintf (buffer, sizeof (buffer), optype_msgid, argp); va_end (argp); + if (d < 1 || d >= (int) sizeof (buffer)) /* Reject truncation. */ + gfc_internal_error ("optype_msgid overflow: %d", d); if (op1->rank != op2->rank) { diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index 61663fec7e5..d7bd0545173 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -60,9 +60,12 @@ gfc_get_string (const char *format, ...) } else { + int ret; va_start (ap, format); - vsnprintf (temp_name, sizeof (temp_name), format, ap); + ret = vsnprintf (temp_name, sizeof (temp_name), format, ap); va_end (ap); + if (ret < 1 || ret >= (int) sizeof (temp_name)) /* Reject truncation. */ + gfc_internal_error ("identifier overflow: %d", ret); temp_name[sizeof (temp_name) - 1] = 0; str = temp_name; } diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index cde34c67482..fc3354f0457 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -3142,25 +3142,9 @@ gfc_new_symbol (const char *name, gfc_namespace *ns) gfc_clear_ts (&p->ts); gfc_clear_attr (&p->attr); p->ns = ns; - p->declared_at = gfc_current_locus; - - if (strlen (name) > GFC_MAX_SYMBOL_LEN) - gfc_internal_error ("new_symbol(): Symbol name too long"); - p->name = gfc_get_string ("%s", name); - /* Make sure flags for symbol being C bound are clear initially. */ - p->attr.is_bind_c = 0; - p->attr.is_iso_c = 0; - - /* Clear the ptrs we may need. */ - p->common_block = NULL; - p->f2k_derived = NULL; - p->assoc = NULL; - p->dt_next = NULL; - p->fn_result_spec = 0; - return p; }