2639 Commits

Author SHA1 Message Date
Jonas Jensen
5f6d07dd57 C++: Fix performance of UnsignedGEZero.ql
This query used two fastTC operations that were already somewhat
inefficient on their own but could send the evaluator into an OOM loop
when run in parallel without enough RAM.

The fix is to recurse manually, starting just from the expressions that
are potential candidates for alerts.
2020-02-26 11:32:41 +01:00
Geoffrey White
73446ea610 Merge pull request #2511 from jbj/isInCycle-raw-only
C++: Compute isInCycle only for raw IR
2019-12-12 14:22:00 +00:00
Jonas Jensen
66876d0f63 C++: Compute isInCycle only for raw IR
On wireshark/wireshark, `isInCycle` ran into a low-memory loop on the
`aliased_ssa` stage. It shouldn't be necessary to detect cycles after
the `raw` stage, so this commit moves cycle detection into the
`Construction` modules and makes it a no-op in `SSAConstruction.qll`.
2019-12-10 16:03:39 +01:00
Jonas Jensen
7c151644f5 C++: Fix getTempVariable join order in IR
This join order seems to have broken so it took forever on
wireshark/wireshark.
2019-12-10 13:43:36 +01:00
Jonas Jensen
9bbebfc01f C++: Add new queries to C suite too 2019-12-09 17:00:33 +01:00
Jonas Jensen
ff7b6e2ce7 C++: Add new queries in 1.23 to legacy suites
I didn't add `JapaneseEraDate.ql` since it's not displayed on LGTM by
default.
2019-12-09 15:36:51 +01:00
Anders Schack-Mulligen
333d0a69d2 Java/C++/C#: Bugfix for field flow through reverse read. 2019-11-29 09:38:24 +01:00
Geoffrey White
1d26d4c5e4 Merge pull request #2404 from jbj/signed-overflow-macro
C++: Fix SignedOverflowCheck.ql performance
2019-11-25 15:15:57 +00:00
Jonas Jensen
5ee19c5a66 C++: Stricter loop-variant check
The `loopVariant` predicate in `ComparisonWithWiderType.ql` is intended
to identify loop counters, but it was too much of a stretch to apply it
to any subexpression of the small side of the comparison.

This change fixes two false positives on arvidn/libtorrent and many
others seen in the wild (on Linux, CoreCLR, ffmpeg, ...).
2019-11-25 11:31:41 +01:00
Jonas Jensen
eb0b0d1e7f C++: Fix remaining FP on MAME
This should fix a FP in libretro/mame2003-plus-libretro.
2019-11-22 16:05:17 +01:00
Geoffrey White
9471134064 Merge pull request #2417 from jbj/enclosing-reeval
C++: Prevent cached stages from being re-evaluated
2019-11-22 09:55:01 +00:00
Jonas Jensen
bd4fa10ffb C++: Tie macro exclusion to <, not +
This fixes a failing qltest and makes the exclusion similar to what's in
`PointerOverflow.ql`. It's possible we should exclude based on both `+`
and `<`, but we can revisit that if false positives show up.
2019-11-22 09:20:00 +01:00
Jonas Jensen
0e4ed1cbbf C++: Prevent cached stages from being re-evaluated
Before this change, evaluating `cpp/constant-comparison` followed by
`cpp/signed-overflow-check` would result in re-evaluation of almost all
the cached stages they share: CFG, basic blocks, SSA, and range
analysis. The same effect could be seen on `cpp/bad-strncpy-size`, which
also uses the GVN library.
2019-11-22 08:45:49 +01:00
Dave Bartolomeo
fb67d3eae4 C++: Fix override errors in MagicDraw.qll 2019-11-21 13:18:45 -07:00
Dave Bartolomeo
27cc6b1e4f C++/C#: Fix compilation error in PrintSSA.qll
We were privately importing `semmle.code.<lang>.ir.internal.Overlap`, but `PrintSSA.qll` was depending on it being public. This is made a little more complicated by the presence of cross-langage pyrameterized modules.
2019-11-21 13:18:25 -07:00
Jonas Jensen
f98cd673fd C++: Autoformat 2019-11-21 14:02:53 +01:00
Jonas Jensen
7f26f078eb C++: Fix isFromMacroDefinition join order
This fixes the performance of `SignedOverflowCheck.ql` on
jluttine/suitesparse.
2019-11-21 11:01:50 +01:00
Jonas Jensen
82499b035b C++: Use isFromMacroDefinition for exclusion
The `SignedOverflowCheck.ql` query was very slow on certain snapshots
(jluttine/suitesparse and Chromium) due to bad magic in
`MacroInvocation::getAnAffectedElement_dispred#fb`. This commit doesn't
fix the bad magic but changes the exclusion mechanism to use a predicate
where we can better control the magic and optimization.

The query should also give more good results due to this new exclusion
mechanism, which is the same one used in its sibling,
`PointerOverflow.ql`.
2019-11-21 10:40:36 +01:00
Robert Marsh
53709deb9d Merge pull request #2342 from jbj/overflow-doc-fixes
C++: Signed Overflow Check qhelp improvements
2019-11-19 15:37:52 -08:00
Jonas Jensen
466f7fe6b2 C++: Use <ol> for recommendations 2019-11-19 12:57:02 +01:00
Jonas Jensen
74ca0e428d Merge pull request #2334 from rdmarsh2/rdmarsh/cpp/reword-pointeroverflow-qhelp
C++: simplify PointerOverflow.qhelp
2019-11-18 08:37:19 +01:00
Robert Marsh
85314c42a9 Update cpp/ql/src/Likely Bugs/Memory Management/PointerOverflow.qhelp
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-15 10:38:58 -08:00
Jonas Jensen
7d7d166113 C++: Remove whitespace at end of line 2019-11-15 11:21:08 +01:00
Jonas Jensen
6bdfebea96 C++: Rename i to n1 in all examples
I see no reason why the Recommendation and Example sections should use
different variable names for the same thing.
2019-11-15 11:20:00 +01:00
Jonas Jensen
9b89602a86 C++: Make var name in qhelp match source snippet 2019-11-15 11:16:34 +01:00
Jonas Jensen
7485cc76b2 C++: Edit Recommendation section
1. The two last examples were misleading at best. The first of those two
   recommended casting to non-negative `int`s to `unsigned int` and then
   checking if their addition would overflow, but overflow was
   impossible because their sum (on 32-bit two's complement) could be at
   most 2^32 - 2. The second example could lead to the wrong condition
   (unsigned overflow) being checked if taken literally. Instead of
   keeping that example, I reworeded the first paragraph of the
   Recommendation section.
2. The assumptions about `delta` being positive was relaxed to
   non-negative.
3. There was no need to assume that an unsigned short was non-negative.
4. Some of the suggestions were missing `i >`.
2019-11-15 11:05:00 +01:00
Jonas Jensen
73d9cc2e7b Merge pull request #2309 from geoffw0/cpp418
CPP: QLDoc enhancements
2019-11-15 08:46:08 +01:00
Robert Marsh
562f62879f C++: rename variables in PointerOverflow examples 2019-11-14 15:21:26 -08:00
Robert Marsh
c6d848caf9 C++: simplify PointerOverflow.qhelp 2019-11-14 15:11:39 -08:00
Dave Bartolomeo
81262d5948 Merge pull request #2328 from geoffw0/routinetest
CPP: Add a quick test of RoutineType.
2019-11-14 15:49:13 -07:00
Geoffrey White
7408726f41 Merge pull request #2312 from jbj/pointer-wraparound-query
C++: New query: Pointer overflow check
2019-11-14 16:13:04 +00:00
Geoffrey White
f2b7af7437 CPP: Add example code for RoutineType. 2019-11-14 15:25:00 +00:00
Geoffrey White
dc34fa366c CPP: Add a test of RoutineType. 2019-11-14 15:13:52 +00:00
Nick Rolfe
f5513342d6 C++: add missing backtick in qldoc comment 2019-11-14 13:20:41 +00:00
Geoffrey White
beb3602253 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:49:02 +00:00
Geoffrey White
6724632413 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:48:50 +00:00
Geoffrey White
45cc6c445c Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:48:05 +00:00
Geoffrey White
0bb37c17f2 CPP: Delete parenthesized comment. 2019-11-14 12:46:43 +00:00
Geoffrey White
8b30baf656 CPP: Delete 'compiler-generated'. 2019-11-14 12:43:54 +00:00
Geoffrey White
f96cffa1f3 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:41:10 +00:00
Geoffrey White
82c6ff02b2 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:40:53 +00:00
Geoffrey White
6262cee27d Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:40:41 +00:00
Geoffrey White
fe5bd42203 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:40:29 +00:00
Geoffrey White
d8aeedfe01 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:40:11 +00:00
Geoffrey White
877e9ba6d8 Update cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:39:54 +00:00
Geoffrey White
acefadda8c Update cpp/ql/src/semmle/code/cpp/exprs/Assignment.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:35:15 +00:00
Geoffrey White
b1dfc60422 Update cpp/ql/src/semmle/code/cpp/exprs/Cast.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 12:34:13 +00:00
Jonas Jensen
c7176e50ca C++: Tweak wording in docs 2019-11-14 13:03:34 +01:00
Geoffrey White
79a000d88f Update cpp/ql/src/semmle/code/cpp/exprs/Expr.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 11:31:27 +00:00
Geoffrey White
0f2a2cb956 Update cpp/ql/src/semmle/code/cpp/exprs/Expr.qll
Co-Authored-By: Jonas Jensen <jbj@github.com>
2019-11-14 11:31:01 +00:00