From patchwork Thu Mar 28 21:52:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1917591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=anlauf@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=l3pUYGrM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V5HMr19ykz1yXw for ; Fri, 29 Mar 2024 08:52:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75B6C3858D39 for ; Thu, 28 Mar 2024 21:52:52 +0000 (GMT) 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.17.21]) by sourceware.org (Postfix) with ESMTPS id 967483858D20; Thu, 28 Mar 2024 21:52:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 967483858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 967483858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711662752; cv=none; b=C6u6IQDoOkgo5tC7ExEHRivR8BoAHwT8hfKzaXExM9VAgPNdXGI2HjzQ41BWo6XQSTElwGAz9XFrKLbUkxHItjXP6jRLTz35/+F74pr76ntJa5a1Uq31Sj1BlI0a16UL8whKKFzqZRtFXW3NLfsk4OeZ3v3XfPsMFjjX3gne3Sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711662752; c=relaxed/simple; bh=RYLgGCUyDSI8CZiTykFGyH/uIQxd0IX+BWm8Pm2VAIQ=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=HmZGW989nAgD6NbW1BI17bix+1ifUtphnHiyVRlU+HhWEjflo3SvymsKJA06bxhrEUq5hJ02Vu6NMM5LvgRdFc569MndaAutGjw4LCYgWdwTLySMDJpU+8Bjyfxd0qgPkns6Ya1VG7ht+UMeJoCNgPjdXETRPKcQcds8fv8S+TY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1711662749; x=1712267549; i=anlauf@gmx.de; bh=Ixc8FKVQghfllJQLlngcv6qZySqMbKLUdY279kgIgao=; h=X-UI-Sender-Class:From:To:Subject:Date; b=l3pUYGrMvS9uosESGoa/6Z5VGYzwvMrye70Hos/R6hjy299Bn11L95RirVx1S2sG GFZrCl/NmVRW4I2k7koJFWsjXCyUtfB9el4wPXWGynru82GjrewxSChJEkJyjwksb eJCR07KWsOy3xLrghSnm1LugoWXwOXxh73Q2k+HSZflDprP582O62X0aJ4JHsMCru bqXy6QeUmxi05Z7FmEN9ZCQT+LOJIZYlJHnY2NMIiRTIxy462lc0I716mdfSyU1P1 Uy3TMIPR7ZkQoNEZMB2flK2ENL9Nur83sgz2O+uPDhuJUXQx2vqE1O+XBQuX5qpzu k4d1GFYkf9pQrtyTOQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.88.174] ([93.207.88.174]) by web-mail.gmx.net (3c-app-gmx-bap16.server.lan [172.19.172.86]) (via HTTP); Thu, 28 Mar 2024 22:52:29 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix NULL pointer dereference on overlapping initialization [PR50410] Date: Thu, 28 Mar 2024 22:52:29 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:mhinwgyCkLVEd+4wPSmN2yJcNM/ztxK1dGu1YAnBGnWiE3xSEHHOwZf0wQkkGZZeU1Tt8 JPXj+wJCRrKN8X/gmgL0lLoQCChaoRebCd/9nNy3XxhEOibkEoyQubhCCfyyA1u2Py1SmjMspgxM Iiv/El/iXCvla971ubXE1xIvi1ylsHjOQ0B9DDBtmFaPZiPN1GL284ZUXaY/xqj3E59OdFiZpmQ5 aWJLqxfcHURCO8WlWLD+grBcxxFmUDJZE+Xfz6AKe2BWsxPjMsKB0jMN4+B9dPaVJnERkwpOZaBP 7I= UI-OutboundReport: notjunk:1;M01:P0:Dl2/crcz/os=;S4gGXobguvWWjiedoOSy5FXQBLf i85hg1g7PSraaq2gnf1EWqS8gt4HLqbEnj1mQLg4EwwWBraAEDf0SY5oddk+aBIFh4O02+Uqw PjdSgdJ6+LZAxdhM1piZhjKcEkB7yAtCbSruOPobtYytcL9FV4JRLsRlHXK11lim17Uipwfd2 RYexMUm4830uT+VNGoetqPRQXDInpNX5Q9XykpafdqHl8rlC8Gq8coqnAEn0iF9OyYuN8iRQX kfX5VPsckHAg9XlDcT7jjv5uKQp49+1iUpt30v1+mxBMSJarqzQOY36Q7yp0qZAfuK7T2VDaK z6Iq/XbXvsxOCoPkhSBTyTA71L5fKy+hKm96wvnKAxxemYXlI2bdTMqjNDprpBZjIJIatvcaA K2S7UHR3iRGKM5dG3syYzpta1hmH4O3/Jns8rD4S0BHn+EvsJ0/P8z8M/qbnVmh0HJ3YekeJu dbLRVBW5RTCfGF37P4ZAjfciS2JIQh2nngZ7U3wu+L8bDUvJvhtUh4S3vMmWIeaJhXhgs74D4 AuTfPMgWUyjRaT2ZUK27aBuvSCCKSB+WOwXnbUHeXvO1LxziMHEVmTWY0VgMQyBBHGgWkyZze SGUMsjrxTA+wkNWx2PEKJD4/2EwTFuU+pqSFVuj1hp3q8xYih7ReXYkNkbBqM2pru2AYtloX7 nS+5iuEfqm0+2iI23lWVA4lANQYgWiWyd9woiJOxSKuW+sTmqylOfJDVde06cRk= X-Spam-Status: No, score=-12.5 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_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Dear all, the attached simple, obvious and ancient patch from the PR fixes a NULL pointer dereference that occurs on overlapping initializations of derived types/DT components in DATA statements. Gfortran currently does not detect or report overlapping initializations in such cases, and some other compilers also do not (Intel) or give only a warning (e.g. Nvidia). For this reason I decided to add -std=legacy to the options in the testcase. Detecting the overlapping initializations appears to require deeper changes in the way we look up DT components when handling DATA statements, which is beyond the current stage. Regtested on x86_64-pc-linux-gnu. I intend to commit soon unless there are objections. Thanks, Harald From b3970a30679959eed159dffa816899e4430e9da5 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 28 Mar 2024 22:34:40 +0100 Subject: [PATCH] Fortran: fix NULL pointer dereference on overlapping initialization [PR50410] gcc/fortran/ChangeLog: PR fortran/50410 * trans-expr.cc (gfc_conv_structure): Check for NULL pointer. gcc/testsuite/ChangeLog: PR fortran/50410 * gfortran.dg/data_initialized_4.f90: New test. --- gcc/fortran/trans-expr.cc | 2 +- gcc/testsuite/gfortran.dg/data_initialized_4.f90 | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/data_initialized_4.f90 diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 76bed9830c4..7ce798ab8a5 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -9650,7 +9650,7 @@ gfc_conv_structure (gfc_se * se, gfc_expr * expr, int init) cm = expr->ts.u.derived->components; for (c = gfc_constructor_first (expr->value.constructor); - c; c = gfc_constructor_next (c), cm = cm->next) + c && cm; c = gfc_constructor_next (c), cm = cm->next) { /* Skip absent members in default initializers and allocatable components. Although the latter have a default initializer diff --git a/gcc/testsuite/gfortran.dg/data_initialized_4.f90 b/gcc/testsuite/gfortran.dg/data_initialized_4.f90 new file mode 100644 index 00000000000..156b6607edf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/data_initialized_4.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! { dg-additional-options "-std=legacy" } +! +! PR fortran/50410 +! +! Silently allow overlapping initialization in legacy mode (used to ICE) + +program p + implicit none + type t + integer :: g = 1 + end type t + type(t) :: u = t(2) + data u%g /3/ + print *, u ! this might print "2" +end -- 2.35.3