5007 Commits

Author SHA1 Message Date
Cornelius Riemenschneider
3f7d68178c Use stripTopLevelSpecifiers() to get the allocated element type for malloc(). 2020-04-27 12:46:14 +02:00
Cornelius Riemenschneider
92e8604fa1 Provide getAllocatedElementType predicate for AllocationExprs.
This predicate tries to determine the type of the allocated elements of an allocation expression.
2020-04-27 12:41:19 +02:00
Cornelius Riemenschneider
203315ae33 Assign malloc results in test to variables. 2020-04-27 12:40:35 +02:00
Geoffrey White
230e5a3a9a Merge pull request #3326 from Cornelius-Riemenschneider/alloc-size-mul
C++: Allocation.qll: Analyze common pattern of malloc() invocations to provide more accurate getSizeMult()
2020-04-27 11:18:54 +01:00
Jonas Jensen
20c956e0a9 Merge pull request #3320 from Semmle/rdmarsh/cpp/taint-tracking-util-port
C++: move logic from DefaultTaintTracking into TaintTrackingUtil
2020-04-27 11:34:03 +02:00
Cornelius Riemenschneider
a50d5b7c6a Accept changed test output. 2020-04-27 09:17:16 +02:00
Robert Marsh
4eea62cbde Merge pull request #3345 from Cornelius-Riemenschneider/openssl-allocators
C++: Allocation.qll: Add support for openssl allocation/deallocation functions.
2020-04-24 14:48:05 -07:00
Jonas Jensen
718f4cd3f9 C++: Speed up SuspiciousAddWithSizeof select
This `select` clause had become very slow after we started caching
`ElementBase::toString` because the query used string concatenation to
produce alert messages, and those string concatenations were done very
early in the pipeline, producing lots of strings that would be discarded
moments later.

By using `$@` to interpolate elements into strings, the concatenation is
done outside of QL.

Testing on a Chromium snapshot, this commit takes us from

    #select#ff ................ 6m2s

to

    #select#cpe#134#fff ....... 15.2s
2020-04-24 16:18:18 +02:00
Mathias Vorreiter Pedersen
98c2fd8401 Merge branch 'master' into get-an-assigned-value-join-order 2020-04-24 15:03:59 +02:00
Mathias Vorreiter Pedersen
7df45a9bb4 Merge pull request #3316 from jbj/arithTypesMatch-perf
C++: inline arithTypesMatch predicate
2020-04-24 09:13:02 +02:00
Jonas Jensen
d98e956c2b Merge pull request #3322 from felicitymay/merge-124-master
Merge rc/1.24 into master
2020-04-24 08:48:54 +02:00
Cornelius Riemenschneider
c25eb19b18 Add support for openssl allocation/deallocation functions. 2020-04-24 01:57:14 +02:00
Cornelius Riemenschneider
0ea7fedeb0 Address review and fix bug in deconstructSizeExpr/3.
Logic is hard, and I made a mistake inverting the formula for the second case, so the
predicate never held for a sizeExpr like sizeof(int)*sizeof(void).
Now, this case is correctly handled by the fallback.
2020-04-23 16:39:29 +02:00
Cornelius Riemenschneider
492f1f446a Remove pragma[inline] from deconstructSizeExpr/3. 2020-04-23 15:53:11 +02:00
Mathias Vorreiter Pedersen
deff2820c2 C++: Modernize getAnAssignedValue following PR comments 2020-04-23 14:14:35 +02:00
Jonas Jensen
37e3bc4b3e C++: invoke unique without | |
Based on PR feedback. This will avoid a syntactic wart and make the
invocation do the right thing both with and without
`language[monotonicAggregates]`.
2020-04-23 13:10:05 +02:00
Jonas Jensen
312e6229fb Merge pull request #3330 from MathiasVP/libc-assert
C++: Generalize charpred of LibcAssert
2020-04-23 13:06:41 +02:00
Cornelius Riemenschneider
a33b7f8c99 Make getSizeMult() functional. 2020-04-23 12:15:31 +02:00
Jonas Jensen
d6f77c0f98 Merge pull request #3328 from MathiasVP/literal-comment
C++: Remove unnecessary part of comment
2020-04-23 11:10:16 +02:00
Mathias Vorreiter Pedersen
0fb534c79e C++: Fix join order in getAnAssignedValue 2020-04-23 11:04:40 +02:00
Jonas Jensen
f696594d35 Merge pull request #3295 from MathiasVP/field-flow-single-struct
C++: Add PostUpdateNode for updates to structs with no chi instructions
2020-04-23 10:02:10 +02:00
Jonas Jensen
cbed175931 Merge pull request #3273 from Semmle/rdmarsh/cpp/RemoteFlowSource-model
C++: Add remote flow sources via models
2020-04-23 09:54:40 +02:00
Mathias Vorreiter Pedersen
1016a0c0db C++: Generalize charpred of LibcAssert 2020-04-23 09:48:30 +02:00
Mathias Vorreiter Pedersen
7b51d0c8a5 C++: Remove unnecessary part of comment 2020-04-23 08:35:44 +02:00
Cornelius Riemenschneider
293e6466d4 AllocationExpr.getSizeMult() now analyzes the size expression of function calls.
This yields more precise size information in a lot of the common cases of C allocation code,
as the common pattern malloc(count * sizeof(type)) is now understood.
2020-04-23 02:05:31 +02:00
Cornelius Riemenschneider
247fc42ec5 Add tests that show AllocationExpr.getSizeMult() behaviour. 2020-04-23 02:02:57 +02:00
Robert Marsh
0dc797d288 C++: autoformat ModelUtil.qll 2020-04-22 16:14:58 -07:00
Robert Marsh
ac22e7950c C++: autoformat FlowSources.qll 2020-04-22 16:11:33 -07:00
Robert Marsh
471f536326 Merge pull request #3307 from dbartol/dbartol/BinaryConditional
C++: IR translation for binary conditional operator
2020-04-22 15:01:16 -07:00
Felicity Chapman
89bf35cd43 Merge branch 'rc/1.24' into merge-124-master
Conflicts:
	change-notes/1.24/analysis-javascript.md
    Resolved in favor of the rc/1.24 branch
2020-04-22 19:01:47 +01:00
Dave Bartolomeo
163ecd97de Merge pull request #3277 from geoffw0/rangeshift
C++: Support for & and >> in SimpleRangeAnalysis
2020-04-22 11:36:36 -04:00
Jonas Jensen
448bd2be87 C++: Make Declaration not abstract
It looks like this change will stop `SignedOverflowCheck.ql` from
needlessly re-evaluating several cached stages.
2020-04-22 17:34:18 +02:00
Jonas Jensen
7a3663976b C++: inline arithTypesMatch predicate
This predicate is effectively a Cartesian product between all enum
types. It's infeasible to compute it in full, so luckily the optimizer
has been able to apply enough magic to make it feasible. That's not a
robust solution, and it has indeed broken on at least one version of the
1.24 release candidate.

On a Chromium snapshot where I ran the LGTM suite overnight, the
`m#MistypedFunctionArguments::arithTypesMatch#bb` predicate (magic for
`arithTypesMatch`) took 170m5s. That was commit b69fdf5 from the
internal repo. I tried to reproduce it in VSCode, this time with commit
646646, but it wasn't quite as bad: the predicate took only 38 seconds.
In any case, making the problematic predicate `pragma[inline]` removes
the slow magic and makes the `MistypedFunctionArguments.ql` query
faster.
2020-04-22 15:14:07 +02:00
Dave Bartolomeo
66381e89ef C++: Add comment from PR feedback 2020-04-22 08:11:43 -04:00
Robert Marsh
9e0d6e8aa0 C++: move taint step cases to TaintTrackingUtil 2020-04-22 01:38:00 -07:00
Geoffrey White
2e392516c2 Apply suggestions from code review
Co-Authored-By: Dave Bartolomeo <dbartol@github.com>
2020-04-22 09:09:16 +01:00
Robert Marsh
52b1fb703d C++: use models in TaintTrackingUtil 2020-04-21 17:18:14 -07:00
Robert Marsh
11683fa9cb C++: add mapping between models and instructions 2020-04-21 17:10:45 -07:00
Dave Bartolomeo
4b44afef90 C++: Accept syntax-zoo test output 2020-04-21 09:42:24 -04:00
Dave Bartolomeo
fee557001e C++: Update SignAnalysis test results 2020-04-21 09:34:44 -04:00
Mathias Vorreiter Pedersen
a49d22e6e4 C++: Fix join ordering 2020-04-21 13:25:06 +02:00
Dave Bartolomeo
1428811f75 C++: IR translation for binary conditional operator
IR generation was not handling the special two-operand flavor of the `?:` operator that GCC supports as an extension. The extractor doesn't quite give us enough information to do this correctly (see github/codeql-c-extractor-team#67), but we can get pretty close.

About half of the code could be shared between the two-operand and three-operand flavors. The main differences for the two-operand flavor are:
1. The "then" operand isn't a child of the `ConditionalExpr`. Instead, we just reuse the original value of the "condition" operand, skipping any implicit cast to `bool` (see comment for rationale).
2. For the three-operand flavor, we generate the condition as control flow rather than the computation of a `bool` value, to avoid creating unnecessarily complicated branching. For the two-operand version, we just compute the value, since we have to reuse that value in the "then" branch anyway.

I've added IR tests for these new cases. I've also updated the expectations for `SignAnalysis.ql` based on the fix. @rdmarsh2, can you please double-check that these diffs look correct? I believe they do, but you're the range/sign analysis expert.
2020-04-21 02:05:21 -04:00
Robert Marsh
d0bb5ad4e2 C++: rename and add description to hasFlowSource 2020-04-20 13:25:31 -07:00
Robert Marsh
e6630a8fba Apply suggestions from code review
Co-Authored-By: Jonas Jensen <jbj@github.com>
2020-04-20 10:14:13 -07:00
Jonas Jensen
875daae84b Merge pull request #3151 from dbartol/dbartol/floats
C++: Better support for complex numbers in IR and AST
2020-04-20 16:27:20 +02:00
Mathias Vorreiter Pedersen
8be1bfe8d0 C++: Add comments and accept expected dataflow sanity failures 2020-04-20 14:13:12 +02:00
Mathias Vorreiter Pedersen
7ba4526f50 C++: Add noinline to StdString constructor 2020-04-20 13:36:41 +02:00
Mathias Vorreiter Pedersen
e0cd595d54 C++: Reduce intermediate tuple counts 2020-04-20 11:46:10 +02:00
Mathias Vorreiter Pedersen
a6e619ce5b C++: Add field flow through single-field structs and accept tests 2020-04-20 08:52:46 +02:00
Mathias Vorreiter Pedersen
6fca23bc8b C++: Demonstrate lack of flow through single-field structs 2020-04-20 08:50:31 +02:00