From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 83B55385800C; Fri, 19 Feb 2021 08:34:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 83B55385800C Received: by mail-lj1-x22d.google.com with SMTP id e17so16014176ljl.8; Fri, 19 Feb 2021 00:34:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wDKbjxHlnFvy+Eo3gyI/3eBQEQH0WDljQHgz+TI8cGc=; b=EuN5QNHoe26gdODaudbmYdXEmTjOCyb+UMATMxIelIUjHVl4hzuQV+XCyxmVtOLSaJ 45A0TY8T5baLCq1AsKFqu/G5709EaXhhC2pA2YMZWYBHrfozGqZtEZYU0rrEyw2Lu6eU xNEQGheJb6P3Mgmm3Jizu9tbtoX+ha44cFgJXhPkCA3lgCxQNpA8BN2KsLEx1meaI6y0 vjset8X3MfqH5uEAGHm9X1IMVheOkY0kwcvFIJh0KOzk8Nzxx6DFXeacQevlPFUbhnLc +wcDd3DPojPQIVoq8Y3zR4gfN9y2bblmd8ILYioGCxKt3n+u9taleA01+Wa4iH+C6gP7 iyBw== X-Gm-Message-State: AOAM533oz6wVYUzKUVnBNfvXnxmwq+C7V2quKaKEf9F8d89qd4QimW+j ncRSVIfMiqD0lQawn0O1FnonTgMGswOpNukLxYY= X-Google-Smtp-Source: ABdhPJz2m4jfzvS/YpQvcrq8gunR0CAkE2iDCxdxcGoZ9Ktqwp3y6JUCSO9+QDGz5W0TsHvKruiKVwq9DzkdWkC2Lfc= X-Received: by 2002:a2e:97d5:: with SMTP id m21mr2761075ljj.373.1613723692232; Fri, 19 Feb 2021 00:34:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Paul Richard Thomas Date: Fri, 19 Feb 2021 08:34:40 +0000 Message-ID: Subject: Re: [PATCH] PR fortran/99147 - Sanitizer detects heap-use-after-free in gfc_add_flavor To: Harald Anlauf Cc: fortran , gcc-patches X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Feb 2021 08:34:55 -0000 Hi Harald, It looks 'obvious' to me too and is certainly OK for master. Thanks Paul On Thu, 18 Feb 2021 at 21:30, Harald Anlauf via Fortran wrote: > Dear all, > > the PR reports an issue detected with an ASAN instrumented compiler, > which can also be verified with valgrind. It appears that the state > of gfc_new_block could be such that it should not be dereferenced. > Reversing the order of condition evaluation helped. > > I failed to find out why this should happen, but then other places > in the code put dereferences of gfc_new_block behind other checks. > Simple things like initializing gfc_new_block with NULL in decl.c > did not help. > > Regtested on x86_64-pc-linux-gnu. No testcase added since the issue > can be found only with an instrumented compiler or valgrind. > > I consider the patch to be obvious and trivial, but post it here > in case somebody wants to dig deeper. > > OK for master? > > Thanks, > Harald > > > PR fortran/99147 - Sanitizer detects heap-use-after-free in gfc_add_flavor > > Reverse order of conditions to avoid invalid read. > > gcc/fortran/ChangeLog: > > * symbol.c (gfc_add_flavor): Reverse order of conditions. > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein