Skip to content

Commit 9b8b364

Browse files
Merge from master
2 parents c389432 + 18b28b1 commit 9b8b364

File tree

107 files changed

+8138
-245
lines changed

Some content is hidden

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

107 files changed

+8138
-245
lines changed

change-notes/1.23/analysis-javascript.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
| **Query** | **Expected impact** | **Change** |
2323
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
2424
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false-positive results | This rule now recognizes additional ways delimiters can be stripped away. |
25-
| Client-side cross-site scripting (`js/xss`) | More results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized. |
25+
| Client-side cross-site scripting (`js/xss`) | More results, fewer false-positive results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized, and more sanitizers are detected. |
2626
| Code injection (`js/code-injection`) | More results | More potential vulnerabilities involving functions that manipulate DOM event handler attributes are now recognized. |
2727
| Hard-coded credentials (`js/hardcoded-credentials`) | Fewer false-positive results | This rule now flags fewer password examples. |
2828
| Illegal invocation (`js/illegal-invocation`) | Fewer false-positive results | This rule now correctly handles methods named `call` and `apply`. |
29-
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases.
29+
| Incorrect suffix check (`js/incorrect-suffix-check`) | Fewer false-positive results | The query recognizes valid checks in more cases. |
3030
| 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. |
3131
| Password in configuration file (`js/password-in-configuration-file`) | Fewer false-positive results | This rule now flags fewer password examples. |
3232
| 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. |
33+
| Reflected cross-site scripting (`js/reflected-xss`) | Fewer false-positive results | The query now recognizes more sanitizers. |
34+
| Stored cross-site scripting (`js/stored-xss`) | Fewer false-positive results | The query now recognizes more sanitizers. |
3335
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now treats responses from servers as untrusted. |
3436

3537
## Changes to QL libraries

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class Expr extends StmtParent, @expr {
131131
valuebind(_, underlyingElement(this))
132132
or
133133
addressConstantExpression(this)
134+
or
135+
constantTemplateLiteral(this)
134136
}
135137

136138
/**
@@ -1119,3 +1121,17 @@ private predicate isStandardPlacementNewAllocator(Function operatorNew) {
11191121

11201122
// Pulled out for performance. See QL-796.
11211123
private predicate hasNoConversions(Expr e) { not e.hasConversion() }
1124+
1125+
/**
1126+
* Holds if `e` is a literal of unknown value in a template, or a cast thereof.
1127+
* We assume that such literals are constant.
1128+
*/
1129+
private predicate constantTemplateLiteral(Expr e) {
1130+
// Unknown literals in uninstantiated templates could be enum constant
1131+
// accesses or pointer-to-member literals.
1132+
e instanceof Literal and
1133+
e.isFromUninstantiatedTemplate(_) and
1134+
not exists(e.getValue())
1135+
or
1136+
constantTemplateLiteral(e.(Cast).getExpr())
1137+
}

cpp/ql/src/semmle/code/cpp/exprs/Literal.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class HexLiteral extends Literal {
132132
* A C/C++ aggregate literal.
133133
*/
134134
class AggregateLiteral extends Expr, @aggregateliteral {
135-
// if this is turned into a Literal we need to change mayBeImpure
136135
override string getCanonicalQLClass() { result = "AggregateLiteral" }
137136

138137
/**
@@ -145,6 +144,10 @@ class AggregateLiteral extends Expr, @aggregateliteral {
145144
result = this.(ClassAggregateLiteral).getFieldExpr(f)
146145
}
147146

147+
override predicate mayBeImpure() { this.getAChild().mayBeImpure() }
148+
149+
override predicate mayBeGloballyImpure() { this.getAChild().mayBeGloballyImpure() }
150+
148151
/** Gets a textual representation of this aggregate literal. */
149152
override string toString() { result = "{...}" }
150153
}

cpp/ql/src/semmle/code/cpp/internal/AddressConstantExpression.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ private predicate constantAddressLValue(Expr lvalue) {
3232
// tells us how it's going to be used.
3333
lvalue.(FunctionAccess).getType() instanceof RoutineType
3434
or
35+
// Pointer-to-member literals in uninstantiated templates
36+
lvalue instanceof Literal and
37+
not exists(lvalue.getValue()) and
38+
lvalue.isFromUninstantiatedTemplate(_)
39+
or
3540
// String literals have array types and undergo array-to-pointer conversion.
3641
lvalue instanceof StringLiteral
3742
or
@@ -61,6 +66,10 @@ private predicate constantAddressPointer(Expr pointer) {
6166
// tells us how it's going to be used.
6267
pointer.(FunctionAccess).getType() instanceof FunctionPointerType
6368
or
69+
// Pointer to member function. These accesses are always pointers even though
70+
// their type is `RoutineType`.
71+
pointer.(FunctionAccess).getTarget() instanceof MemberFunction
72+
or
6473
addressConstantVariable(pointer.(VariableAccess).getTarget()) and
6574
pointer.getType().getUnderlyingType() instanceof PointerType
6675
or

cpp/ql/src/semmle/code/cpp/models/interfaces/ArrayFunction.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* Provides an abstract class for accurate modeling of input and output buffers
33
* in library functions when source code is not available. To use this QL
4-
* library, create a QL class extending `BufferFunction` with a characteristic
4+
* library, create a QL class extending `ArrayFunction` with a characteristic
55
* predicate that selects the function or set of functions you are trying to
6-
* model. Within that class, override the predicates provided by `BufferFunction`
6+
* model. Within that class, override the predicates provided by `ArrayFunction`
77
* to match the flow within that function. Finally, add a private import
8-
* statement to `CustomModels.qll`
8+
* statement to `Models.qll`
99
*/
1010

1111
import semmle.code.cpp.Function

cpp/ql/test/library-tests/namespaces/same_name/decls.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | p#0 |
88
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | p#0 |
99
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area |
10-
| same_name.cpp:4:11:4:21 | namespace_a | same_name.cpp:2:11:2:11 | c |
10+
| file://:0:0:0:0 | (global namespace) | same_name.cpp:2:11:2:11 | c |
1111
| same_name.cpp:4:11:4:21 | namespace_a | same_name.cpp:6:12:6:12 | c |
12+
| same_name.cpp:9:11:9:21 | namespace_b | same_name.cpp:11:12:11:12 | c |

cpp/ql/test/library-tests/namespaces/same_name/same_name.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ namespace namespace_a
88

99
namespace namespace_b
1010
{
11-
//const int c = 1;
12-
//
13-
// this example is causing a DBCheck failure along the lines of:
14-
//
15-
// [INVALID_KEY] Relation namespacembrs((@namespace parentid, unique @namespacembr memberid)): Value 132 of key field memberid occurs in several tuples. Two such tuples are: (134,132) and (144,132)
11+
const int c = 1;
1612
}

cpp/ql/test/library-tests/sideEffects/exprs/exprs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
void f1(int p) {
2+
int f1(int p) {
33
int i;
44

55
for (
@@ -11,3 +11,20 @@ void f1(int p) {
1111

1212
return p;
1313
}
14+
15+
int global_int;
16+
17+
int f2(void) {
18+
global_int = 3;
19+
return 1;
20+
}
21+
22+
int f3(void) {
23+
return 2;
24+
}
25+
26+
void f4(void) {
27+
int is0[3] = { 3, 4, 5 };
28+
int is1[3] = { 3, f2(), 5 };
29+
int is2[3] = { 3, f3(), 5 };
30+
}

cpp/ql/test/library-tests/sideEffects/exprs/exprs.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@
1010
| exprs.c:9:3:9:5 | ++ ... | | mayBeImpure | |
1111
| exprs.c:9:5:9:5 | p | isPure | | |
1212
| exprs.c:12:12:12:12 | p | isPure | | |
13+
| exprs.c:18:5:18:14 | global_int | isPure | | |
14+
| exprs.c:18:5:18:18 | ... = ... | | mayBeImpure | mayBeGloballyImpure |
15+
| exprs.c:18:18:18:18 | 3 | isPure | | |
16+
| exprs.c:19:12:19:12 | 1 | isPure | | |
17+
| exprs.c:23:12:23:12 | 2 | isPure | | |
18+
| exprs.c:27:13:27:13 | 3 | isPure | | |
19+
| exprs.c:27:17:27:28 | {...} | isPure | | |
20+
| exprs.c:27:20:27:20 | 3 | isPure | | |
21+
| exprs.c:27:23:27:23 | 4 | isPure | | |
22+
| exprs.c:27:26:27:26 | 5 | isPure | | |
23+
| exprs.c:28:13:28:13 | 3 | isPure | | |
24+
| exprs.c:28:17:28:31 | {...} | | mayBeImpure | mayBeGloballyImpure |
25+
| exprs.c:28:20:28:20 | 3 | isPure | | |
26+
| exprs.c:28:23:28:24 | call to f2 | | mayBeImpure | mayBeGloballyImpure |
27+
| exprs.c:28:29:28:29 | 5 | isPure | | |
28+
| exprs.c:29:13:29:13 | 3 | isPure | | |
29+
| exprs.c:29:17:29:31 | {...} | isPure | | |
30+
| exprs.c:29:20:29:20 | 3 | isPure | | |
31+
| exprs.c:29:23:29:24 | call to f3 | isPure | | |
32+
| exprs.c:29:29:29:29 | 5 | isPure | | |
1333
| exprs.cpp:7:10:7:16 | (...) | isPure | | |
1434
| exprs.cpp:7:10:7:16 | (reference to) | isPure | | |
1535
| exprs.cpp:7:11:7:15 | * ... | isPure | | |

cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_sanity.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ instructionWithoutSuccessor
2020
| ms_try_mix.cpp:11:12:11:15 | Chi: call to C |
2121
| ms_try_mix.cpp:28:12:28:15 | Chi: call to C |
2222
| ms_try_mix.cpp:48:10:48:13 | Chi: call to C |
23-
| pointer_to_member.cpp:35:11:35:21 | FieldAddress: {...} |
23+
| pointer_to_member.cpp:36:11:36:30 | FieldAddress: {...} |
2424
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... |
2525
| vla.c:5:9:5:14 | VariableAddress: definition of matrix |
2626
| vla.c:11:6:11:16 | UnmodeledDefinition: vla_typedef |

0 commit comments

Comments
 (0)