From patchwork Wed Jan 18 21:20:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 45507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2569286wrn; Wed, 18 Jan 2023 13:21:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXu/tkykHayyAKllZE/6Ihi7az+8kEV5mXXX4ykY+QVITmz6ufkw9h/Go4vpJJEXMhF4aVla X-Received: by 2002:a17:907:2119:b0:86e:d375:1f09 with SMTP id qn25-20020a170907211900b0086ed3751f09mr8226237ejb.67.1674076888578; Wed, 18 Jan 2023 13:21:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674076888; cv=none; d=google.com; s=arc-20160816; b=JsHXmMKRowgYWicKmBMx/q0vxH3Hzp91gzb/Zt/fcSwXRxEFOdjyTt5HGxFVKgPV7u YskgOIzhtYMx70Jx6AE+aTwt0GK+3LPIzxviK8Rs2GOpzWF/B62lJpNhhJNFJMIeiX/j IbEtaiTuCZE0XRa19ZirTCLqU2NoeOpUTDUhKPoxvDg05PGqp/eFSIWqI38dsE4JQOUv /S4v/1uexNLD8uKCyeJguCBVv25Wy4nwqOVOfrtyHVVNko+A6ENuhIfAUpWoop50Fg/d lRjy9gg5n49z72SGpjWfUaTEXZHhx1A1wNLOwlH+431LVVY+mkKnXshI4aQJzD1D1x3r n7kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=0AMZuK4K9UyoBWE3mTTYR6zHINhqEk9qoyNQOBlt4HE=; b=HiOJDlI4glLCVwAJBrwGsJyCmWm8YAC6+BNhZDVQEMMY1Tuu4YWHntc4PPi0sBuSsc 3dhRTaqZrvnMg7QBKSLwy9TACueL9aPa/9KBHngL4wvtnEnyM0pGAg72ykYxc4m5GdOs J4t3FgXZt0fX7oETaj6C+mZAiEqI32r/zickhnZEKqIWClWTLqTLEKq9g0izAHDeNSZY p3x/FUcRAUYXF4/OYsRpq/nl9xvrkfPFVdzQ3zg7Qqgxkb1FgoY3SBpWBpbbcTt1KuK6 XJCQ4Gv1Aq1bpbmm3p9fWFKwUaEv00k+HRUlJwgQFNfZsNVYLxwJplLzKJekrvQ8owbq zVxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oqwzR8vG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id nd23-20020a170907629700b007c08bfea555si38897313ejc.121.2023.01.18.13.21.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 13:21:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oqwzR8vG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FE183858C53 for ; Wed, 18 Jan 2023 21:21:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FE183858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674076886; bh=0AMZuK4K9UyoBWE3mTTYR6zHINhqEk9qoyNQOBlt4HE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oqwzR8vGpfdSRxmYZMryZX/GWvvu8TuB28uHP2w3q2aBp8+vtGXB1DVgMDjYSvWih wREWKiYPq8yVsZaqfuZRW57sIn8ZW84W72YyHZ8+nCS+0ftmk+dP9XpZ4MtKvEZ/78 IEcn+Ur1MdH6qUpNnv6+Npas/KoRLzATBAeuLhc4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id 0B7AA3858D28; Wed, 18 Jan 2023 21:20:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B7AA3858D28 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.88.90] ([93.207.88.90]) by web-mail.gmx.net (3c-app-gmx-bs46.server.lan [172.19.170.98]) (via HTTP); Wed, 18 Jan 2023 22:20:42 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery for invalid CLASS component [PR108434] Date: Wed, 18 Jan 2023 22:20:42 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:3yY4qFKpN0gpKHB99Orss90w2U+u3RofiQILMbDov7cPs8BdJkwe4YHnsisHi9OViMb3h ezSEJju/IVV2axfZC9ol3PPUzioP52B4r5O4tpoK8O4cKn/vVOOW98IIoeaz1y4SWMYfXfSflxiL a0ivQi+5B1TUTjh0TPJp4Ktq84eXmxcZp+eR4dS55xQs7xx7kCAJduBJe23sHjQ+TiEBuXbfA38/ j9UORSTcl64gZoa8qOv36B0ODHStEKZUhmGMknos3sGPhDBKxedSO7HQn1saOiB0DH3XHGZ7bSW5 fE= UI-OutboundReport: notjunk:1;M01:P0:0PKZgKPIwb0=;ftvkavdWjh/jCTIJS4teh/Ej0Tp yMIjWRswIapDB1HpxuyBzFIR3cD2rmig60lUhS97wMU8IrWePh/q3/gwScBdZndn/20hs38oy ZlqdblKH9PwjP9fdB1OmaNUhElYfatS77qlJuy2p1OeR4+XkPwyT65JD7IxzMEe9GbSpwxTqm d5JJW8A1hdhRD9AzU9mB9+5/buA6gzKubcnPlbwGjEyvDv7tY0lO1i5U9Eie8IvRBaYzq5vvQ M7XhqQz89MU9ARUIKFTuc2ryLxvXu1R16gACTyamY97ADgrChxlkjGXbaWIHUgesUBLwlpThn 9Gem4O8op3sHOq2OSsVlXcWnggOOj8OGa/diYmr07LhYSPy/+pegC5P4iJO6BPhXfCQClKdVW BJrew41gwJXtavcWFfnR3+ACZQNndNi8thgtpa1mJ3Ie6YZoRTztKkxlhNttQ/KFb6cZ2kA+C Qpha90hsxe1n1zeTyQaBS38RmoID+/+80rFvq44hPNFNP6Iv75xPhlegy6Cp1rTgqIvSZ/dEu U+sbiX3QWTh04gtX+Zmvo7Hn/by588+/vE+MZglMhCti+o+T+vEQC4so8xAKZYhyQP5nzxlkB V2pSQRUvVx2/tTBQ84tM0AzSVspTIDcJ9QKInGykaaBo2xPfynEFlUigMqYuAmFd8JMQCqs5B +msY35hqfK7aiea0cpd3PkyQy+homkx9PMy7HiizKh1XC+Ic3UGweOvOppUrTTWzg8b4PSdQE IfehkiBXgIGzyxCFENCY2Gw0Wg2OfA+JiYU/rpWl8ydNFqvcODIZ69C6Cex8A63/qM6kfh+oh OodIzRuPKdJG6gLWq92y+XaQ== X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755396847148345490?= X-GMAIL-MSGID: =?utf-8?q?1755396847148345490?= Dear all, I intend to commit the attached obvious fix for a NULL pointer dereference within the next 24h unless there are comment or objections. The patch has been checked with valgrind that it prevents invalid reads for the testcase, and it is certainly safe. Regtested on x86_64-pc-linux-gnu. Thanks, Harald From e240637f6c2e2605a8424538bee885d899507506 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 18 Jan 2023 22:13:29 +0100 Subject: [PATCH] Fortran: error recovery for invalid CLASS component [PR108434] gcc/fortran/ChangeLog: PR fortran/108434 * expr.cc (class_allocatable): Prevent NULL pointer dereference or invalid read. (class_pointer): Likewise. gcc/testsuite/ChangeLog: PR fortran/108434 * gfortran.dg/pr108434.f90: New test. --- gcc/fortran/expr.cc | 4 ++-- gcc/testsuite/gfortran.dg/pr108434.f90 | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108434.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 5ec369c9cd8..3036b1be60f 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -4996,14 +4996,14 @@ get_union_initializer (gfc_symbol *union_type, gfc_component **map_p) static bool class_allocatable (gfc_component *comp) { - return comp->ts.type == BT_CLASS && CLASS_DATA (comp) + return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp) && CLASS_DATA (comp)->attr.allocatable; } static bool class_pointer (gfc_component *comp) { - return comp->ts.type == BT_CLASS && CLASS_DATA (comp) + return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp) && CLASS_DATA (comp)->attr.pointer; } diff --git a/gcc/testsuite/gfortran.dg/pr108434.f90 b/gcc/testsuite/gfortran.dg/pr108434.f90 new file mode 100644 index 00000000000..e1768a57574 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108434.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/108434 - ICE in class_allocatable +! Contributed by G.Steinmetz + +program p + type t + class(c), pointer :: a(2) ! { dg-error "must have a deferred shape" } + end type t + class(t), allocatable :: x + class(t), pointer :: y +end -- 2.35.3