From patchwork Sat Dec 8 18:11:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1009880 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-491948-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uwvnLC9Z"; 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 43By8668lmz9s1c for ; Sun, 9 Dec 2018 05:11:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=ak+CO2l2NBR9PXrMvJN4DaY0rJ2+dFNfuPNMOqpXTrD Dk7EK9W8Z4jZw6IFEt/7OE8JXvPMrP6fJlIH6tCJV513nvt4Q6vDOR367Mmgcn8e gVDyUO4sxL7fFs0NKKeeSfRlxjBuZEoJ9nF0xX9g7qYO/XYF/fYdPqmM5ZJS74nw = 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:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=cgyK7KnmKAhV0+YH4YUX2swwBNY=; b=uwvnLC9ZN9VARhO9t tMvEuzEykzDRmBfYORmESk2MspZSHKgk3c4imfMY3loSsF01mSzGIhMDVrlrRbDe MKH90XGxyGq2C57JuZCPxkPeg71XQx1d5kX+lsPuA7gPKaw3ZGWknlTDJoUNJDAx NhGwCSTr0Vqak7xMvwHFp4Txns= Received: (qmail 8257 invoked by alias); 8 Dec 2018 18:11:10 -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 8239 invoked by uid 89); 8 Dec 2018 18:11:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=rank, H*MI:edu X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Dec 2018 18:11:07 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id wB8IB5dV042004 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 8 Dec 2018 10:11:06 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id wB8IB5is042003; Sat, 8 Dec 2018 10:11:05 -0800 (PST) (envelope-from sgk) Date: Sat, 8 Dec 2018 10:11:05 -0800 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Committed] PR fortran/88357 -- NULL pointer dereferences Message-ID: <20181208181105.GA41955@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Invalid code can cause the gfortran to dereference NULL pointers. The patch fixes this. 2018-12-08 Steven G. Kargl PR fortran/88357 * class.c (insert_component_ref): Check for NULL pointer and previous error message issued. * parse.c (parse_associate): Check for NULL pointer. * resolve.c (resolve_assoc_var): Check for NULL pointer. 2018-12-08 Steven G. Kargl * gfortran.dg/pr88357_1.f90: New test. * gfortran.dg/pr88357_2.f90: New test. Index: gcc/fortran/class.c =================================================================== --- gcc/fortran/class.c (revision 266907) +++ gcc/fortran/class.c (working copy) @@ -72,14 +72,18 @@ along with GCC; see the file COPYING3. If not see static void insert_component_ref (gfc_typespec *ts, gfc_ref **ref, const char * const name) { - gfc_symbol *type_sym; gfc_ref *new_ref; + int wcnt, ecnt; gcc_assert (ts->type == BT_DERIVED || ts->type == BT_CLASS); - type_sym = ts->u.derived; - gfc_find_component (type_sym, name, true, true, &new_ref); + gfc_find_component (ts->u.derived, name, true, true, &new_ref); + + gfc_get_errors (&wcnt, &ecnt); + if (ecnt > 0 && !new_ref) + return; gcc_assert (new_ref->u.c.component); + while (new_ref->next) new_ref = new_ref->next; new_ref->next = *ref; Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (revision 266907) +++ gcc/fortran/parse.c (working copy) @@ -4563,7 +4563,7 @@ parse_associate (void) else rank = a->target->rank; /* When the rank is greater than zero then sym will be an array. */ - if (sym->ts.type == BT_CLASS) + if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)) { if ((!CLASS_DATA (sym)->as && rank != 0) || (CLASS_DATA (sym)->as Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 266907) +++ gcc/fortran/resolve.c (working copy) @@ -8715,7 +8715,8 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_targe { /* target's rank is 0, but the type of the sym is still array valued, which has to be corrected. */ - if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as) + if (sym->ts.type == BT_CLASS + && CLASS_DATA (sym) && CLASS_DATA (sym)->as) { gfc_array_spec *as; symbol_attribute attr; Index: gcc/testsuite/gfortran.dg/pr88357_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr88357_1.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr88357_1.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +program p + type t + end type + class(t) :: x[*] ! { dg-error "must be dummy, allocatable or pointer" } + associate (y => x) + end associate +end Index: gcc/testsuite/gfortran.dg/pr88357_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr88357_2.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr88357_2.f90 (working copy) @@ -0,0 +1,8 @@ +! { dg-do compile } +program p + type t + end type + class(t) :: x ! { dg-error "must be dummy, allocatable or pointer" } + associate (y => x) + end associate +end