public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/106147] New: RFE: -fanalyzer could complain about some cases of infinite loops and infinite recursion
@ 2022-06-30 12:46 dmalcolm at gcc dot gnu.org
  2022-06-30 12:57 ` [Bug analyzer/106147] " dmalcolm at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2022-06-30 12:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106147

            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 that
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 the
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 = 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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-20 17:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 12:46 [Bug analyzer/106147] New: RFE: -fanalyzer could complain about some cases of infinite loops and infinite recursion dmalcolm at gcc dot gnu.org
2022-06-30 12:57 ` [Bug analyzer/106147] " dmalcolm at gcc dot gnu.org
2022-07-29 22:20 ` dmalcolm at gcc dot gnu.org
2022-08-10 13:48 ` dmalcolm at gcc dot gnu.org
2022-11-10 20:38 ` dmalcolm at gcc dot gnu.org
2022-11-11 21:04 ` cvs-commit at gcc dot gnu.org
2022-11-11 21:24 ` dmalcolm at gcc dot gnu.org
2023-11-18  0:59 ` cvs-commit at gcc dot gnu.org
2024-01-12 19:14 ` dmalcolm at gcc dot gnu.org
2024-01-20 17:20 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).