Skip to content

Commit 1018eaf

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dataflow-indirect-args
Conflicts: cpp/ql/test/library-tests/dataflow/fields/ir-flow.expected
2 parents 038bea2 + f5e491c commit 1018eaf

File tree

300 files changed

+9429
-3203
lines changed

Some content is hidden

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

300 files changed

+9429
-3203
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## General improvements
44

55
* Support for the following frameworks and libraries has been improved:
6+
- [fstream](https://www.npmjs.com/package/fstream)
67
- [jGrowl](https://github.com/stanlemon/jGrowl)
78
- [jQuery](https://jquery.com/)
89

@@ -21,6 +22,7 @@
2122
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional file system calls. |
2223
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional command execution calls. |
2324
| Expression has no effect (`js/useless-expression`) | Less results | This query no longer flags an expression when that expression is the only content of the containing file. |
25+
| Unknown directive (`js/unknown-directive`) | Less results | This query no longer flags directives generated by the Babel compiler. |
2426

2527
## Changes to libraries
2628

config/identical-files.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@
111111
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IR.qll",
112112
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/IR.qll"
113113
],
114-
"IR IRSanity": [
115-
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRSanity.qll",
116-
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRSanity.qll",
117-
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRSanity.qll",
118-
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRSanity.qll",
119-
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/IRSanity.qll"
114+
"IR IRConsistency": [
115+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRConsistency.qll",
116+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRConsistency.qll",
117+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRConsistency.qll",
118+
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRConsistency.qll",
119+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/IRConsistency.qll"
120120
],
121121
"IR PrintIR": [
122122
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/PrintIR.qll",
@@ -157,10 +157,10 @@
157157
"cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll",
158158
"csharp/ql/src/semmle/code/csharp/ir/implementation/Opcode.qll"
159159
],
160-
"IR SSASanity": [
161-
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSASanity.qll",
162-
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.qll",
163-
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSASanity.qll"
160+
"IR SSAConsistency": [
161+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConsistency.qll",
162+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConsistency.qll",
163+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSAConsistency.qll"
164164
],
165165
"C++ IR InstructionImports": [
166166
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/InstructionImports.qll",

cpp/ql/src/Documentation/CaptionedComments.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import cpp
66

7+
/**
8+
* Gets a string representation of the comment `c` containing the caption 'TODO' or 'FIXME'.
9+
* If `c` spans multiple lines, all lines after the first are abbreviated as [...].
10+
*/
711
string getCommentTextCaptioned(Comment c, string caption) {
812
(caption = "TODO" or caption = "FIXME") and
913
exists(

cpp/ql/src/Documentation/CommentedOutCode.qll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for identifying C/C++ comments that look like code.
3+
*/
4+
15
import cpp
26

37
/**
@@ -137,30 +141,52 @@ class CommentBlock extends Comment {
137141
)
138142
}
139143

144+
/**
145+
* Gets the last comment associated with this comment block.
146+
*/
140147
Comment lastComment() { result = this.getComment(max(int i | exists(this.getComment(i)))) }
141148

149+
/**
150+
* Gets the contents of the `i`'th comment associated with this comment block.
151+
*/
142152
string getLine(int i) {
143153
this instanceof CStyleComment and
144154
result = this.getContents().regexpCapture("(?s)/\\*+(.*)\\*+/", 1).splitAt("\n", i)
145155
or
146156
this instanceof CppStyleComment and result = this.getComment(i).getContents().suffix(2)
147157
}
148158

159+
/**
160+
* Gets the number of lines in the comments associated with this comment block.
161+
*/
149162
int numLines() {
150163
result = strictcount(int i, string line | line = this.getLine(i) and line.trim() != "")
151164
}
152165

166+
/**
167+
* Gets the number of lines that look like code in the comments associated with this comment block.
168+
*/
153169
int numCodeLines() {
154170
result = strictcount(int i, string line | line = this.getLine(i) and looksLikeCode(line))
155171
}
156172

173+
/**
174+
* Holds if the comment block is a C-style comment, and each
175+
* comment line starts with a *.
176+
*/
157177
predicate isDocumentation() {
158178
// If a C-style comment starts each line with a *, then it's
159179
// probably documentation rather than code.
160180
this instanceof CStyleComment and
161181
forex(int i | i in [1 .. this.numLines() - 1] | this.getLine(i).trim().matches("*%"))
162182
}
163183

184+
/**
185+
* Holds if this comment block looks like code that has been commented out. Specifically:
186+
* 1. It does not look like documentation (see `isDocumentation`).
187+
* 2. It is not in a header file without any declaration entries or top level declarations.
188+
* 3. More than half of the lines in the comment block look like code.
189+
*/
164190
predicate isCommentedOutCode() {
165191
not this.isDocumentation() and
166192
not this.getFile().(HeaderFile).noTopLevelCode() and
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @name AST Consistency Check
3+
* @description Performs consistency checks on the Abstract Syntax Tree. This query should have no results.
4+
* @kind table
5+
* @id cpp/ast-consistency-check
6+
*/
7+
8+
import cpp
9+
import CastConsistency

cpp/ql/src/semmle/code/cpp/ASTSanity.ql

Lines changed: 0 additions & 9 deletions
This file was deleted.

cpp/ql/src/semmle/code/cpp/dataflow/EscapesTree.qll

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
44
* passed to a function, or similar.
55
*/
66

7+
/*
8+
* Maintainer note: this file is one of several files that are similar but not
9+
* identical. Many changes to this file will also apply to the others:
10+
* - AddressConstantExpression.qll
11+
* - AddressFlow.qll
12+
* - EscapesTree.qll
13+
*/
14+
715
private import cpp
816

917
/**
1018
* Holds if `f` is an instantiation of the `std::move` or `std::forward`
1119
* template functions, these functions are essentially casts, so we treat them
1220
* as such.
1321
*/
14-
private predicate stdIdentityFunction(Function f) {
15-
f.getNamespace().getParentNamespace() instanceof GlobalNamespace and
16-
f.getNamespace().getName() = "std" and
17-
(
18-
f.getName() = "move"
19-
or
20-
f.getName() = "forward"
21-
)
22-
}
22+
private predicate stdIdentityFunction(Function f) { f.hasQualifiedName("std", ["move", "forward"]) }
23+
24+
/**
25+
* Holds if `f` is an instantiation of `std::addressof`, which effectively
26+
* converts a reference to a pointer.
27+
*/
28+
private predicate stdAddressOf(Function f) { f.hasQualifiedName("std", "addressof") }
2329

2430
private predicate lvalueToLvalueStepPure(Expr lvalueIn, Expr lvalueOut) {
2531
lvalueIn = lvalueOut.(DotFieldAccess).getQualifier().getFullyConverted()
@@ -91,12 +97,17 @@ private predicate lvalueToReferenceStep(Expr lvalueIn, Expr referenceOut) {
9197
}
9298

9399
private predicate referenceToLvalueStep(Expr referenceIn, Expr lvalueOut) {
94-
// This probably cannot happen. It would require an expression to be
95-
// converted to a reference and back again without an intermediate variable
96-
// assignment.
97100
referenceIn.getConversion() = lvalueOut.(ReferenceDereferenceExpr)
98101
}
99102

103+
private predicate referenceToPointerStep(Expr referenceIn, Expr pointerOut) {
104+
pointerOut =
105+
any(FunctionCall call |
106+
stdAddressOf(call.getTarget()) and
107+
referenceIn = call.getArgument(0).getFullyConverted()
108+
)
109+
}
110+
100111
private predicate referenceToReferenceStep(Expr referenceIn, Expr referenceOut) {
101112
referenceOut =
102113
any(FunctionCall call |
@@ -145,6 +156,12 @@ private predicate pointerFromVariableAccess(VariableAccess va, Expr pointer) {
145156
pointerToPointerStep(prev, pointer)
146157
)
147158
or
159+
// reference -> pointer
160+
exists(Expr prev |
161+
referenceFromVariableAccess(va, prev) and
162+
referenceToPointerStep(prev, pointer)
163+
)
164+
or
148165
// lvalue -> pointer
149166
exists(Expr prev |
150167
lvalueFromVariableAccess(va, prev) and
@@ -169,7 +186,8 @@ private predicate referenceFromVariableAccess(VariableAccess va, Expr reference)
169186
private predicate addressMayEscapeAt(Expr e) {
170187
exists(Call call |
171188
e = call.getAnArgument().getFullyConverted() and
172-
not stdIdentityFunction(call.getTarget())
189+
not stdIdentityFunction(call.getTarget()) and
190+
not stdAddressOf(call.getTarget())
173191
or
174192
e = call.getQualifier().getFullyConverted() and
175193
e.getUnderlyingType() instanceof PointerType

0 commit comments

Comments
 (0)