From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id C4A7B3858000 for ; Fri, 26 Nov 2021 12:34:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4A7B3858000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:105:465:1:3:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4J0vM302fzzQjXy; Fri, 26 Nov 2021 13:34:23 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Date: Fri, 26 Nov 2021 13:34:15 +0100 From: Iain Buclaw Subject: Re: [PATCH] d: fix ASAN in option processing To: gcc-patches@gcc.gnu.org, Martin =?iso-8859-2?b?TGm5a2E=?= References: In-Reply-To: MIME-Version: 1.0 Message-Id: <1637929964.iojyfzpfm9.astroid@galago.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 26 Nov 2021 12:34:27 -0000 Excerpts from Martin Li=C5=A1ka's message of November 25, 2021 2:59 pm: > Fixes: >=20 > =3D=3D129444=3D=3DERROR: AddressSanitizer: global-buffer-overflow on addr= ess 0x00000666ca5c at pc 0x000000ef094b bp 0x7fffffff8180 sp 0x7fffffff8178 > READ of size 4 at 0x00000666ca5c thread T0 > #0 0xef094a in parse_optimize_options ../../gcc/d/d-attribs.cc:855 > #1 0xef0d36 in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:= 916 > #2 0xef107e in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:= 887 > #3 0xff85b1 in decl_attributes(tree_node**, tree_node*, int, tree_no= de*) ../../gcc/attribs.c:829 > #4 0xef2a91 in apply_user_attributes(Dsymbol*, tree_node*) ../../gcc= /d/d-attribs.cc:427 > #5 0xf7b7f3 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:134= 6 > #6 0xf87bc7 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:967 > #7 0xf87bc7 in DeclVisitor::visit(FuncDeclaration*) ../../gcc/d/decl= .cc:808 > #8 0xf83db5 in DeclVisitor::build_dsymbol(Dsymbol*) ../../gcc/d/decl= .cc:146 >=20 > for the following test-case: gcc/testsuite/gdc.dg/attr_optimize1.d. >=20 > Ready for master? Thanks, looks OK to me, does it need backporting as well? Iain. > Thanks, > Martin >=20 > gcc/d/ChangeLog: >=20 > * d-attribs.cc (parse_optimize_options): Check index before > accessing cl_options. > --- > gcc/d/d-attribs.cc | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) >=20 > diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc > index d81b7d122f7..1ec800526f7 100644 > --- a/gcc/d/d-attribs.cc > +++ b/gcc/d/d-attribs.cc > @@ -852,7 +852,9 @@ parse_optimize_options (tree args) > unsigned j =3D 1; > for (unsigned i =3D 1; i < decoded_options_count; ++i) > { > - if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZ= ATION)) > + unsigned opt_index =3D decoded_options[i].opt_index; > + if (opt_index >=3D cl_options_count > + && ! (cl_options[opt_index].flags & CL_OPTIMIZATION)) > { > ret =3D false; > warning (OPT_Wattributes, > --=20 > 2.34.0 >=20 >=20