From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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] Content-Type: multipart/mixed; boundary=sgnirk-99b30f3a-c856-459a-bd8f-74745fd2d2ec 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 List-Id: --sgnirk-99b30f3a-c856-459a-bd8f-74745fd2d2ec Content-Type: text/plain; charset=UTF-8 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 --sgnirk-99b30f3a-c856-459a-bd8f-74745fd2d2ec Content-Type: text/x-patch Content-Disposition: attachment; filename=pr50410-part1.diff Content-Transfer-Encoding: quoted-printable =46rom 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. =2D-- 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 =2D-- 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, in= t init) cm =3D expr->ts.u.derived->components; for (c =3D gfc_constructor_first (expr->value.constructor); - c; c =3D gfc_constructor_next (c), cm =3D cm->next) + c && cm; c =3D gfc_constructor_next (c), cm =3D 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/testsu= ite/gfortran.dg/data_initialized_4.f90 new file mode 100644 index 00000000000..156b6607edf =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/data_initialized_4.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! { dg-additional-options "-std=3Dlegacy" } +! +! PR fortran/50410 +! +! Silently allow overlapping initialization in legacy mode (used to ICE) + +program p + implicit none + type t + integer :: g =3D 1 + end type t + type(t) :: u =3D t(2) + data u%g /3/ + print *, u ! this might print "2" +end =2D- 2.35.3 --sgnirk-99b30f3a-c856-459a-bd8f-74745fd2d2ec--