From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 35E2E3842AD3; Thu, 30 Jun 2022 12:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35E2E3842AD3 From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/106147] New: RFE: -fanalyzer could complain about some cases of infinite loops and infinite recursion Date: Thu, 30 Jun 2022 12:46:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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, 30 Jun 2022 12:46:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106147 Bug ID: 106147 Summary: RFE: -fanalyzer could complain about some cases of infinite loops and infinite recursion Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- We can't solve the halting problem, but maybe we can detect some cases where the code *definitely* loops forever or has infinite recursion, where there = are no state changes or possible interactions with the outside world. See: https://cwe.mitre.org/data/definitions/674.html and: https://cwe.mitre.org/data/definitions/835.html Juliet 1.3 has testcases for: (a) CWE674_Uncontrolled_Recursion/ (b) CWE835_Infinite_Loop/ where (a) makes a distinction between actually unbounded vs a buggy loop th= at counts down from UINT_MAX (pushing UINT_MAX stack frames is probably going = to crash). All of the test cases in (b) perform output in an infinite loop, which I'd argue is not a bug, as the program is generating output that's visible to t= he outside world. Compare CWE 835 examples 1 and 2. Example 1 repeatedly calls "connect" in a loop, which I don't think -fanalyzer is going to be able to reason about, whereas 2 has logic: while (inventoryCount > minimumCount) { inventoryCount =3D inventoryCount - rateSold; days++; } where if rateSold is 0, this effectively becomes: while (inventoryCount > minimumCount) { days++; } and thus an infinite loop with no observable effects; possible interaction = with taint (e.g. if rateSold is under attacker control)=