Skip to content

Commit 9f5c37c

Browse files
committed
Merge branch 'master' into copymove
2 parents c4940aa + 63115a3 commit 9f5c37c

File tree

225 files changed

+11132
-3452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+11132
-3452
lines changed

.codeqlmanifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ "provide": [ "*/ql/src/qlpack.yml",
22
"*/ql/test/qlpack.yml",
3+
"*/ql/examples/qlpack.yml",
34
"*/upgrades/qlpack.yml",
45
"misc/legacy-support/*/qlpack.yml",
56
"misc/suite-helpers/qlpack.yml" ] }

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"omnisharp.autoStart": false
3+
}

change-notes/1.25/analysis-csharp.md

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,51 @@ The following changes in version 1.25 affect C# analysis in all applications.
2828
such as `A<int>.B`, no longer are considered unbound generics. (Such nested types do,
2929
however, still have relevant `.getSourceDeclaration()`s, for example `A<>.B`.)
3030
* The data-flow library has been improved, which affects most security queries by potentially
31-
adding more results. Flow through methods now takes nested field reads/writes into account.
32-
For example, the library is able to track flow from `"taint"` to `Sink()` via the method
33-
`GetF2F1()` in
34-
```csharp
35-
class C1
36-
{
37-
string F1;
38-
}
39-
40-
class C2
41-
{
42-
C1 F2;
43-
44-
string GetF2F1() => F2.F1; // Nested field read
45-
46-
void M()
47-
{
48-
F2 = new C1() { F1 = "taint" };
49-
Sink(GetF2F1()); // NEW: "taint" reaches here
50-
}
51-
}
52-
```
31+
adding more results:
32+
- Flow through methods now takes nested field reads/writes into account.
33+
For example, the library is able to track flow from `"taint"` to `Sink()` via the method
34+
`GetF2F1()` in
35+
```csharp
36+
class C1
37+
{
38+
string F1;
39+
}
40+
41+
class C2
42+
{
43+
C1 F2;
44+
45+
string GetF2F1() => F2.F1; // Nested field read
46+
47+
void M()
48+
{
49+
F2 = new C1() { F1 = "taint" };
50+
Sink(GetF2F1()); // NEW: "taint" reaches here
51+
}
52+
}
53+
```
54+
- Flow through collections is now modeled precisely. For example, instead of modeling an array
55+
store `a[i] = x` as a taint-step from `x` to `a`, we now model it as a data-flow step that
56+
stores `x` into `a`. To get the value back out, a matching read step must be taken.
57+
58+
For source-code based data-flow analysis, the following constructs are modeled as stores into
59+
collections:
60+
- Direct array assignments, `a[i] = x`.
61+
- Array initializers, `new [] { x }`.
62+
- C# 6-style array initializers, `new C() { Array = { [i] = x } }`.
63+
- Call arguments that match a `params` parameter, where the C# compiler creates an array under-the-hood.
64+
- `yield return` statements.
65+
66+
The following source-code constructs read from a collection:
67+
- Direct array reads, `a[i]`.
68+
- `foreach` statements.
69+
70+
For calls out to library code, existing flow summaries have been refined to precisely
71+
capture how they interact with collection contents. For example, a call to
72+
`System.Collections.Generic.List<T>.Add(T)` stores the value of the argument into the
73+
qualifier, and a call to `System.Collections.Generic.List<T>.get_Item(int)` (that is, an
74+
indexer call) reads contents out of the qualifier. Moreover, the effect of
75+
collection-clearing methods such as `System.Collections.Generic.List<T>.Clear()` is now
76+
also modeled.
5377

5478
## Changes to autobuilder

change-notes/1.25/analysis-javascript.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
- [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
77
- [bluebird](http://bluebirdjs.com/)
88
- [express](https://www.npmjs.com/package/express)
9+
- [execa](https://www.npmjs.com/package/execa)
910
- [fancy-log](https://www.npmjs.com/package/fancy-log)
1011
- [fastify](https://www.npmjs.com/package/fastify)
12+
- [foreground-child](https://www.npmjs.com/package/foreground-child)
1113
- [fstream](https://www.npmjs.com/package/fstream)
1214
- [jGrowl](https://github.com/stanlemon/jGrowl)
1315
- [jQuery](https://jquery.com/)
@@ -17,6 +19,7 @@
1719
- [mssql](https://www.npmjs.com/package/mssql)
1820
- [mysql](https://www.npmjs.com/package/mysql)
1921
- [npmlog](https://www.npmjs.com/package/npmlog)
22+
- [opener](https://www.npmjs.com/package/opener)
2023
- [pg](https://www.npmjs.com/package/pg)
2124
- [sequelize](https://www.npmjs.com/package/sequelize)
2225
- [spanner](https://www.npmjs.com/package/spanner)

cpp/ql/examples/qlpack.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: codeql-cpp-examples
2+
version: 0.0.0
3+
libraryPathDependencies: codeql-cpp

cpp/ql/src/codeql-suites/cpp-lgtm-full.qls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99
tags contain:
1010
- ide-contextual-queries/local-definitions
1111
- ide-contextual-queries/local-references
12+
- query: Metrics/Dependencies/ExternalDependencies.ql
13+
- query: Metrics/Dependencies/ExternalDependenciesSourceLinks.ql
14+
- query: Metrics/Files/FLinesOfCode.ql
15+
- query: Metrics/Files/FLinesOfCommentedOutCode.ql
16+
- query: Metrics/Files/FLinesOfComments.ql
17+
- query: Metrics/Files/FLinesOfDuplicatedCode.ql
18+
- query: Metrics/Files/FNumberOfTests.ql

cpp/ql/src/semmle/code/cpp/Element.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class Element extends ElementBase {
197197
initialisers(underlyingElement(this), unresolveElement(result), _, _) or
198198
exprconv(unresolveElement(result), underlyingElement(this)) or
199199
param_decl_bind(underlyingElement(this), _, unresolveElement(result)) or
200-
using_container(unresolveElement(result), underlyingElement(this))
200+
using_container(unresolveElement(result), underlyingElement(this)) or
201+
static_asserts(unresolveElement(this), _, _, _, underlyingElement(result))
201202
}
202203

203204
/** Gets the closest `Element` enclosing this one. */
@@ -278,12 +279,12 @@ class StaticAssert extends Locatable, @static_assert {
278279
/**
279280
* Gets the expression which this static assertion ensures is true.
280281
*/
281-
Expr getCondition() { static_asserts(underlyingElement(this), unresolveElement(result), _, _) }
282+
Expr getCondition() { static_asserts(underlyingElement(this), unresolveElement(result), _, _, _) }
282283

283284
/**
284285
* Gets the message which will be reported by the compiler if this static assertion fails.
285286
*/
286-
string getMessage() { static_asserts(underlyingElement(this), _, result, _) }
287+
string getMessage() { static_asserts(underlyingElement(this), _, result, _, _) }
287288

288-
override Location getLocation() { static_asserts(underlyingElement(this), _, _, result) }
289+
override Location getLocation() { static_asserts(underlyingElement(this), _, _, result, _) }
289290
}

cpp/ql/src/semmle/code/cpp/Variable.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class TemplateVariable extends Variable {
582582
* float a;
583583
* }
584584
*
585-
* template<type T>
585+
* template<typename T>
586586
* void myTemplateFunction() {
587587
* T b;
588588
* }

cpp/ql/src/semmle/code/cpp/commons/Printf.qll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ predicate primitiveVariadicFormatter(TopLevelFunction f, int formatParamIndex) {
4949
)
5050
}
5151

52+
/**
53+
* A standard function such as `vsprintf` that has an output parameter
54+
* and a variable argument list of type `va_arg`.
55+
*/
56+
private predicate primitiveVariadicFormatterOutput(TopLevelFunction f, int outputParamIndex) {
57+
// note: this might look like the regular expression in `primitiveVariadicFormatter`, but
58+
// there is one important difference: the [fs] part is not optional, as these classify
59+
// the `printf` variants that write to a buffer.
60+
// Conveniently, these buffer parameters are all at index 0.
61+
f.getName().regexpMatch("_?_?va?[fs]n?w?printf(_s)?(_p)?(_l)?") and outputParamIndex = 0
62+
}
63+
5264
private predicate callsVariadicFormatter(Function f, int formatParamIndex) {
5365
exists(FunctionCall fc, int i |
5466
variadicFormatter(fc.getTarget(), i) and
@@ -57,6 +69,26 @@ private predicate callsVariadicFormatter(Function f, int formatParamIndex) {
5769
)
5870
}
5971

72+
private predicate callsVariadicFormatterOutput(Function f, int outputParamIndex) {
73+
exists(FunctionCall fc, int i |
74+
fc.getEnclosingFunction() = f and
75+
variadicFormatterOutput(fc.getTarget(), i) and
76+
fc.getArgument(i) = f.getParameter(outputParamIndex).getAnAccess()
77+
)
78+
}
79+
80+
/**
81+
* Holds if `f` is a function such as `vprintf` that takes variable argument list
82+
* of type `va_arg` and writes formatted output to a buffer given as a parameter at
83+
* index `outputParamIndex`, if any.
84+
*/
85+
private predicate variadicFormatterOutput(Function f, int outputParamIndex) {
86+
primitiveVariadicFormatterOutput(f, outputParamIndex)
87+
or
88+
not f.isVarargs() and
89+
callsVariadicFormatterOutput(f, outputParamIndex)
90+
}
91+
6092
/**
6193
* Holds if `f` is a function such as `vprintf` that has a format parameter
6294
* (at `formatParamIndex`) and a variable argument list of type `va_arg`.
@@ -78,6 +110,8 @@ class UserDefinedFormattingFunction extends FormattingFunction {
78110
UserDefinedFormattingFunction() { isVarargs() and callsVariadicFormatter(this, _) }
79111

80112
override int getFormatParameterIndex() { callsVariadicFormatter(this, result) }
113+
114+
override int getOutputParameterIndex() { callsVariadicFormatterOutput(this, result) }
81115
}
82116

83117
/**

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,20 @@ predicate localExprFlow(Expr e1, Expr e2) { localFlow(exprNode(e1), exprNode(e2)
699699
*/
700700
class BarrierGuard extends IRGuardCondition {
701701
/** Override this predicate to hold if this guard validates `instr` upon evaluating to `b`. */
702-
abstract predicate checks(Instruction instr, boolean b);
702+
predicate checksInstr(Instruction instr, boolean b) { none() }
703+
704+
/** Override this predicate to hold if this guard validates `expr` upon evaluating to `b`. */
705+
predicate checks(Expr e, boolean b) { none() }
703706

704707
/** Gets a node guarded by this guard. */
705708
final Node getAGuardedNode() {
706709
exists(ValueNumber value, boolean edge |
710+
(
711+
this.checksInstr(value.getAnInstruction(), edge)
712+
or
713+
this.checks(value.getAnInstruction().getConvertedResultExpression(), edge)
714+
) and
707715
result.asInstruction() = value.getAnInstruction() and
708-
this.checks(value.getAnInstruction(), edge) and
709716
this.controls(result.asInstruction().getBlock(), edge)
710717
)
711718
}

0 commit comments

Comments
 (0)