From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 32DBB3857C4A; Thu, 17 Mar 2022 11:34:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32DBB3857C4A From: "siddhesh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104964] Wrong *** buffer overflow detected ***: terminated - acl Date: Thu, 17 Mar 2022 11:34:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: siddhesh at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: siddhesh at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 11:34:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104964 Siddhesh Poyarekar changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |siddhesh at gcc dot= gnu.org --- Comment #5 from Siddhesh Poyarekar --- I'm not 100% sure if it's invalid code, but I was just about to write that = it depends on what the pass ends up seeing. If earlier passes end up optimizi= ng the code such that the objsz pass sees the malloc first (e.g. the reproduce= r in pr104961), it ends up with the malloc'd size, otherwise it ends up with the declared size. So if it was: struct bad_struct {=20 struct g=20=20=20=20=20=20=20=20=20=20 {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 char s_str[1];=20=20 } i;=20=20=20=20=20=20=20=20=20=20=20=20=20=20 };=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 and struct g *i =3D &bad->i;=20=20=20=20=20=20 strcpy (i->s_str, "sparta"); then i tends to get optimized as a MEM_REF of the malloc'd block, letting us see the extra space. This needs to be fixed, but then it's possibly a different bug from the one you're seeing in acl since this affects __bos too, not just __bdos. (I'm off in a couple of hours btw, returning on Tuesday so I may not get to= it until then)=