Skip to content

Commit ac6554b

Browse files
author
Esben Sparre Andreasen
authored
Merge branch 'master' into js/improve-getAResponseDataNode
2 parents 9aa0e71 + 396a72d commit ac6554b

File tree

220 files changed

+7644
-2844
lines changed

Some content is hidden

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

220 files changed

+7644
-2844
lines changed

change-notes/1.23/analysis-csharp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ The following changes in version 1.23 affect C# analysis in all applications.
3636
picture of the partial flow paths from a given source. The feature is
3737
disabled by default and can be enabled for individual configurations by
3838
overriding `int explorationLimit()`.
39+
* `foreach` statements where the body is guaranteed to be executed at least once, such as `foreach (var x in new string[]{ "a", "b", "c" }) { ... }`, are now recognized by all analyses based on the control flow graph (such as SSA, data flow and taint tracking).
3940

4041
## Changes to autobuilder

change-notes/1.23/analysis-javascript.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@
1313

1414
| **Query** | **Tags** | **Purpose** |
1515
|---------------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
16+
| Unused index variable (`js/unused-index-variable`) | correctness | Highlights loops that iterate over an array, but do not use the index variable to access array elements, indicating a possible typo or logic error. |
1617

1718

1819
## Changes to existing queries
1920

2021
| **Query** | **Expected impact** | **Change** |
2122
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
23+
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false-positive results | This rule now recognizes additional ways delimiters can be stripped away. |
2224
| Client-side cross-site scripting (`js/xss`) | More results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized. |
2325
| Code injection (`js/code-injection`) | More results | More potential vulnerabilities involving functions that manipulate DOM event handler attributes are now recognized. |
26+
| Hard-coded credentials (`js/hardcoded-credentials`) | Fewer false-positive results | This rule now flags fewer password examples. |
2427
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases.
2528
| Network data written to file (`js/http-to-file-access`) | Fewer false-positive results | This query has been renamed to better match its intended purpose, and now only considers network data untrusted. |
29+
| Password in configuration file (`js/password-in-configuration-file`) | Fewer false-positive results | This rule now flags fewer password examples. |
2630
| Prototype pollution (`js/prototype-pollution`) | More results | The query now highlights vulnerable uses of jQuery and Angular, and the results are shown on LGTM by default. |
2731
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now treats responses from servers as untrusted. |
2832

config/identical-files.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"TaintTracking::Configuration Java/C++/C#": [
3030
"cpp/ql/src/semmle/code/cpp/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
3131
"cpp/ql/src/semmle/code/cpp/dataflow/internal/tainttracking2/TaintTrackingImpl.qll",
32+
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
33+
"cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/tainttracking2/TaintTrackingImpl.qll",
3234
"csharp/ql/src/semmle/code/csharp/dataflow/internal/tainttracking1/TaintTrackingImpl.qll",
3335
"csharp/ql/src/semmle/code/csharp/dataflow/internal/tainttracking2/TaintTrackingImpl.qll",
3436
"csharp/ql/src/semmle/code/csharp/dataflow/internal/tainttracking3/TaintTrackingImpl.qll",

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

Lines changed: 123 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ import semmle.code.cpp.Initializer
44
private import semmle.code.cpp.internal.ResolveClass
55

66
/**
7-
* A C/C++ variable.
7+
* A C/C++ variable. For example, in the following code there are four
8+
* variables, `a`, `b`, `c` and `d`:
9+
* ```
10+
* extern int a;
11+
* int a;
12+
*
13+
* void myFunction(int b) {
14+
* int c;
15+
* }
16+
*
17+
* namespace N {
18+
* extern int d;
19+
* int d = 1;
20+
* }
21+
* ```
822
*
923
* For local variables, there is a one-to-one correspondence between
1024
* `Variable` and `VariableDeclarationEntry`.
@@ -162,7 +176,22 @@ class Variable extends Declaration, @variable {
162176
}
163177

164178
/**
165-
* A particular declaration or definition of a C/C++ variable.
179+
* A particular declaration or definition of a C/C++ variable. For example, in
180+
* the following code there are six variable declaration entries - two each for
181+
* `a` and `d`, and one each for `b` and `c`:
182+
* ```
183+
* extern int a;
184+
* int a;
185+
*
186+
* void myFunction(int b) {
187+
* int c;
188+
* }
189+
*
190+
* namespace N {
191+
* extern int d;
192+
* int d = 1;
193+
* }
194+
* ```
166195
*/
167196
class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
168197
override Variable getDeclaration() { result = getVariable() }
@@ -183,13 +212,13 @@ class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
183212
* because the parameter may have a different name in the declaration
184213
* than in the definition. For example:
185214
*
186-
* ```
187-
* // Declaration. Parameter is named "x".
188-
* int f(int x);
215+
* ```
216+
* // Declaration. Parameter is named "x".
217+
* int f(int x);
189218
*
190-
* // Definition. Parameter is named "y".
191-
* int f(int y) { return y; }
192-
* ```
219+
* // Definition. Parameter is named "y".
220+
* int f(int y) { return y; }
221+
* ```
193222
*/
194223
override string getName() { var_decls(underlyingElement(this), _, _, result, _) and result != "" }
195224

@@ -215,7 +244,13 @@ class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
215244

216245
/**
217246
* A parameter as described within a particular declaration or definition
218-
* of a C/C++ function.
247+
* of a C/C++ function. For example the declaration of `a` in the following
248+
* code:
249+
* ```
250+
* void myFunction(int a) {
251+
* int b;
252+
* }
253+
* ```
219254
*/
220255
class ParameterDeclarationEntry extends VariableDeclarationEntry {
221256
ParameterDeclarationEntry() { param_decl_bind(underlyingElement(this), _, _) }
@@ -272,8 +307,17 @@ class ParameterDeclarationEntry extends VariableDeclarationEntry {
272307

273308
/**
274309
* A C/C++ variable with block scope [N4140 3.3.3]. In other words, a local
275-
* variable or a function parameter. Local variables can be static; use the
276-
* `isStatic` member predicate to detect those.
310+
* variable or a function parameter. For example, the variables `a`, `b` and
311+
* `c` in the following code:
312+
* ```
313+
* void myFunction(int a) {
314+
* int b;
315+
* static int c;
316+
* }
317+
* ```
318+
*
319+
* Local variables can be static; use the `isStatic` member predicate to
320+
* detect those.
277321
*/
278322
class LocalScopeVariable extends Variable, @localscopevariable {
279323
/** Gets the function to which this variable belongs. */
@@ -292,6 +336,14 @@ deprecated class StackVariable extends Variable {
292336
/**
293337
* A C/C++ local variable. In other words, any variable that has block
294338
* scope [N4140 3.3.3], but is not a parameter of a `Function` or `CatchBlock`.
339+
* For example the variables `b` and `c` in the following code:
340+
* ```
341+
* void myFunction(int a) {
342+
* int b;
343+
* static int c;
344+
* }
345+
* ```
346+
*
295347
* Local variables can be static; use the `isStatic` member predicate to detect
296348
* those.
297349
*
@@ -310,7 +362,15 @@ class LocalVariable extends LocalScopeVariable, @localvariable {
310362
}
311363

312364
/**
313-
* A C/C++ variable which has global scope or namespace scope.
365+
* A C/C++ variable which has global scope or namespace scope. For example the
366+
* variables `a` and `b` in the following code:
367+
* ```
368+
* int a;
369+
*
370+
* namespace N {
371+
* int b;
372+
* }
373+
* ```
314374
*/
315375
class GlobalOrNamespaceVariable extends Variable, @globalvariable {
316376
override string getName() { globalvariables(underlyingElement(this), _, result) }
@@ -321,7 +381,15 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
321381
}
322382

323383
/**
324-
* A C/C++ variable which has namespace scope.
384+
* A C/C++ variable which has namespace scope. For example the variable `b`
385+
* in the following code:
386+
* ```
387+
* int a;
388+
*
389+
* namespace N {
390+
* int b;
391+
* }
392+
* ```
325393
*/
326394
class NamespaceVariable extends GlobalOrNamespaceVariable {
327395
NamespaceVariable() {
@@ -330,7 +398,15 @@ class NamespaceVariable extends GlobalOrNamespaceVariable {
330398
}
331399

332400
/**
333-
* A C/C++ variable which has global scope.
401+
* A C/C++ variable which has global scope. For example the variable `a`
402+
* in the following code:
403+
* ```
404+
* int a;
405+
*
406+
* namespace N {
407+
* int b;
408+
* }
409+
* ```
334410
*
335411
* Note that variables declared in anonymous namespaces have namespace scope,
336412
* even though they are accessed in the same manner as variables declared in
@@ -341,7 +417,15 @@ class GlobalVariable extends GlobalOrNamespaceVariable {
341417
}
342418

343419
/**
344-
* A C structure member or C++ member variable.
420+
* A C structure member or C++ member variable. For example the member
421+
* variables `m` and `s` in the following code:
422+
* ```
423+
* class MyClass {
424+
* public:
425+
* int m;
426+
* static int s;
427+
* };
428+
* ```
345429
*
346430
* This includes static member variables in C++. To exclude static member
347431
* variables, use `Field` instead of `MemberVariable`.
@@ -395,7 +479,12 @@ deprecated class FunctionPointerMemberVariable extends MemberVariable {
395479
}
396480

397481
/**
398-
* A C++14 variable template.
482+
* A C++14 variable template. For example, in the following code the variable
483+
* template `v` defines a family of variables:
484+
* ```
485+
* template<class T>
486+
* T v;
487+
* ```
399488
*/
400489
class TemplateVariable extends Variable {
401490
TemplateVariable() { is_variable_template(underlyingElement(this)) }
@@ -410,7 +499,24 @@ class TemplateVariable extends Variable {
410499
* A non-static local variable or parameter that is not part of an
411500
* uninstantiated template. Uninstantiated templates are purely syntax, and
412501
* only on instantiation will they be complete with information about types,
413-
* conversions, call targets, etc.
502+
* conversions, call targets, etc. For example in the following code, the
503+
* variables `a` in `myFunction` and `b` in the instantiation
504+
* `myTemplateFunction<int>`, but not `b` in the template
505+
* `myTemplateFunction<T>`:
506+
* ```
507+
* void myFunction() {
508+
* T a;
509+
* }
510+
*
511+
* template<type T>
512+
* void myTemplateFunction() {
513+
* T b;
514+
* }
515+
*
516+
* ...
517+
*
518+
* myTemplateFunction<int>();
519+
* ```
414520
*/
415521
class SemanticStackVariable extends LocalScopeVariable {
416522
SemanticStackVariable() {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,17 @@ class MicrosoftInt64Type extends IntegralType {
166166
not isExplicitlySigned()
167167
}
168168
}
169+
170+
/**
171+
* The `__builtin_va_list` type, used to provide variadic functionality.
172+
*
173+
* This is a complement to the `__builtin_va_start`, `__builtin_va_end`,
174+
* `__builtin_va_copy` and `__builtin_va_arg` expressions.
175+
*/
176+
class BuiltInVarArgsList extends Type {
177+
BuiltInVarArgsList() {
178+
this.hasName("__builtin_va_list")
179+
}
180+
181+
override string getCanonicalQLClass() { result = "BuiltInVarArgsList" }
182+
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ abstract private class AccessPath extends TAccessPath {
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
12621262
override string toString() {
1263-
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(" : " + ppReprType(t)))
12641264
}
12651265

12661266
override AccessPathFront getFront() {
@@ -1647,6 +1647,11 @@ private predicate pathSuccPlus(PathNode n1, PathNode n2) = fastTC(pathSucc/2)(n1
16471647
module PathGraph {
16481648
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
16491649
query predicate edges(PathNode a, PathNode b) { pathSucc(a, b) }
1650+
1651+
/** Holds if `n` is a node in the graph of data flow path explanations. */
1652+
query predicate nodes(PathNode n, string key, string val) {
1653+
reach(n) and key = "semmle.label" and val = n.toString()
1654+
}
16501655
}
16511656

16521657
/**

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ abstract private class AccessPath extends TAccessPath {
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
12621262
override string toString() {
1263-
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(" : " + ppReprType(t)))
12641264
}
12651265

12661266
override AccessPathFront getFront() {
@@ -1647,6 +1647,11 @@ private predicate pathSuccPlus(PathNode n1, PathNode n2) = fastTC(pathSucc/2)(n1
16471647
module PathGraph {
16481648
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
16491649
query predicate edges(PathNode a, PathNode b) { pathSucc(a, b) }
1650+
1651+
/** Holds if `n` is a node in the graph of data flow path explanations. */
1652+
query predicate nodes(PathNode n, string key, string val) {
1653+
reach(n) and key = "semmle.label" and val = n.toString()
1654+
}
16501655
}
16511656

16521657
/**

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ abstract private class AccessPath extends TAccessPath {
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
12621262
override string toString() {
1263-
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(" : " + ppReprType(t)))
12641264
}
12651265

12661266
override AccessPathFront getFront() {
@@ -1647,6 +1647,11 @@ private predicate pathSuccPlus(PathNode n1, PathNode n2) = fastTC(pathSucc/2)(n1
16471647
module PathGraph {
16481648
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
16491649
query predicate edges(PathNode a, PathNode b) { pathSucc(a, b) }
1650+
1651+
/** Holds if `n` is a node in the graph of data flow path explanations. */
1652+
query predicate nodes(PathNode n, string key, string val) {
1653+
reach(n) and key = "semmle.label" and val = n.toString()
1654+
}
16501655
}
16511656

16521657
/**

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ abstract private class AccessPath extends TAccessPath {
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
12621262
override string toString() {
1263-
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(" : " + ppReprType(t)))
12641264
}
12651265

12661266
override AccessPathFront getFront() {
@@ -1647,6 +1647,11 @@ private predicate pathSuccPlus(PathNode n1, PathNode n2) = fastTC(pathSucc/2)(n1
16471647
module PathGraph {
16481648
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
16491649
query predicate edges(PathNode a, PathNode b) { pathSucc(a, b) }
1650+
1651+
/** Holds if `n` is a node in the graph of data flow path explanations. */
1652+
query predicate nodes(PathNode n, string key, string val) {
1653+
reach(n) and key = "semmle.label" and val = n.toString()
1654+
}
16501655
}
16511656

16521657
/**

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ abstract private class AccessPath extends TAccessPath {
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
12621262
override string toString() {
1263-
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(" : " + ppReprType(t)))
12641264
}
12651265

12661266
override AccessPathFront getFront() {
@@ -1647,6 +1647,11 @@ private predicate pathSuccPlus(PathNode n1, PathNode n2) = fastTC(pathSucc/2)(n1
16471647
module PathGraph {
16481648
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
16491649
query predicate edges(PathNode a, PathNode b) { pathSucc(a, b) }
1650+
1651+
/** Holds if `n` is a node in the graph of data flow path explanations. */
1652+
query predicate nodes(PathNode n, string key, string val) {
1653+
reach(n) and key = "semmle.label" and val = n.toString()
1654+
}
16501655
}
16511656

16521657
/**

0 commit comments

Comments
 (0)