Skip to content

Commit ec62657

Browse files
authored
Merge pull request #161 from adityasharad/merge/1.18-master-050918
Merge rc/1.18 into master.
2 parents 5fcd663 + f279452 commit ec62657

File tree

145 files changed

+620
-373
lines changed

Some content is hidden

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

145 files changed

+620
-373
lines changed

change-notes/1.18/analysis-cpp.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| [Nested loops with same variable] | Fewer false positive results | Results where the loop variable is a member of a class or struct now account for the object. |
2020
| [For loop variable changed in body] | Fewer false positive results | Results where the loop variable is a member of a class or struct now account for the object. |
2121
| [Local variable hides global variable] | Fewer false positive results | Results for parameters are now only reported if the name of the global variable is the same as the name of the parameter as used in the function definition (not just a function declaration). |
22+
| [Memory may not be freed] | More correct results | This query now models calls to `realloc` more accurately. |
2223
| Wrong number of arguments to formatting function | Fewer false positive results | Some false positives related to custom printf-like functions have been fixed. |
2324
| Wrong number of arguments to formatting function | Clear separation between results of high and low severity | This query has been split into two queries: a high-severity query named [Too few arguments to formatting function] and a low-severity query named [Too many arguments to formatting function]. |
2425
| [Too few arguments to formatting function] | More correct and fewer false positives results | This query now understands positional format arguments as supported by some libraries. |
@@ -34,5 +35,6 @@
3435
## Changes to QL libraries
3536

3637
* Fixes for aggregate initializers using designators:
37-
** `ClassAggregateLiteral.getFieldExpr()` previously assumed initializer expressions appeared in the same order as the declaration order of the fields, causing it to associate the expressions with the wrong fields when using designated initializers. This has been fixed.
38-
** `ArrayAggregateLiteral.getElementExpr()` previously assumed initializer expressions appeared in the same order as the corresponding array elements, causing it to associate the expressions with the wrong array elements when using designated initializers. This has been fixed.
38+
* `ClassAggregateLiteral.getFieldExpr()` previously assumed initializer expressions appeared in the same order as the declaration order of the fields, causing it to associate the expressions with the wrong fields when using designated initializers. This has been fixed.
39+
* `ArrayAggregateLiteral.getElementExpr()` previously assumed initializer expressions appeared in the same order as the corresponding array elements, causing it to associate the expressions with the wrong array elements when using designated initializers. This has been fixed.
40+
* `Element.getEnclosingElement()` no longer includes macro accesses in its results. To explore parents and children of macro accesses, use the relevant member predicates on `MacroAccess` or `MacroInvocation`.

change-notes/1.18/analysis-javascript.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
* Modelling of re-export declarations has been improved. This may result in fewer false-positive results for a variety of queries.
1212

13-
* Modelling of taint flow through the array operations `map` and `join` has been improved. This may give additional results for the security queries.
13+
* Modelling of taint flow through array operations has been improved. This may give additional results for the security queries.
1414

1515
* The taint tracking library recognizes more ways in which taint propagates. In particular, some flow through string formatters is now recognized. This may give additional results for the security queries.
1616

@@ -85,6 +85,8 @@
8585
- [xss](https://github.com/leizongmin/js-xss)
8686
- [xtend](https://github.com/Raynos/xtend)
8787

88+
* Handling of ambient TypeScript code has been improved. As a result, fewer false positives will be reported in `.d.ts` files.
89+
8890
## New queries
8991

9092
| **Query** | **Tags** | **Purpose** |
@@ -103,7 +105,7 @@
103105
| Comparison between inconvertible types | Lower severity | The severity of this rule has been revised to "warning". |
104106
| CORS misconfiguration for credentials transfer | More true-positive results | This rule now treats header names case-insensitively. |
105107
| Hard-coded credentials | More true-positive results | This rule now recognizes secret cryptographic keys. |
106-
| Incomplete sanitization | More true-positive results | This rule now recognizes incomplete URL encoding and decoding. |
108+
| Incomplete string escaping or encoding | Better name, more true-positive results | This rule has been renamed to more clearly reflect its purpose. Also, it now recognizes incomplete URL encoding and decoding. |
107109
| Insecure randomness | More true-positive results | This rule now recognizes secret cryptographic keys. |
108110
| Missing rate limiting | More true-positive results, fewer false-positive results | This rule now recognizes additional rate limiters and expensive route handlers. |
109111
| Missing X-Frame-Options HTTP header | Fewer false-positive results | This rule now treats header names case-insensitively. |
@@ -122,6 +124,6 @@
122124

123125
* HTTP and HTTPS requests made using the Node.js `http.request` and `https.request` APIs and the Electron `Electron.net.request` and `Electron.ClientRequest` APIs are modeled as `RemoteFlowSources`.
124126
* HTTP header names are now always normalized to lower case to reflect the fact that they are case insensitive. In particular, the result of `HeaderDefinition.getAHeaderName`, and the first parameter of `HeaderDefinition.defines`, `ExplicitHeaderDefinition.definesExplicitly` and `RouteHandler.getAResponseHeader` is now always a lower-case string.
125-
* New AST nodes for TypeScript 2.9 features have been added.
127+
* New AST nodes have been added for TypeScript 2.9 and 3.0 features.
126128
* The class `JsonParseCall` has been deprecated. Use `JsonParserCall` instead.
127129
* The handling of spread arguments in the data flow library has been changed: `DataFlow::InvokeNode.getArgument(i)` is now only defined when there is no spread argument at or before argument position `i`, and similarly `InvokeNode.getNumArgument` is only defined for invocations without spread arguments.

config/identical-files.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
{
22
"C++ IR Instruction": [
3-
"cpp/ql/src/semmle/code/cpp/ir/internal/Instruction.qll",
4-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/Instruction.qll",
5-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/Instruction.qll"
3+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll",
4+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll",
5+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll"
66
],
77
"C++ IR IRBlock": [
8-
"cpp/ql/src/semmle/code/cpp/ir/internal/IRBlock.qll",
9-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/IRBlock.qll",
10-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/IRBlock.qll"
8+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRBlock.qll",
9+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRBlock.qll",
10+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll"
1111
],
1212
"C++ IR IRVariable": [
13-
"cpp/ql/src/semmle/code/cpp/ir/internal/IRVariable.qll",
14-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/IRVariable.qll",
15-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/IRVariable.qll"
13+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRVariable.qll",
14+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRVariable.qll",
15+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRVariable.qll"
1616
],
1717
"C++ IR FunctionIR": [
18-
"cpp/ql/src/semmle/code/cpp/ir/internal/FunctionIR.qll",
19-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/FunctionIR.qll",
20-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/FunctionIR.qll"
18+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/FunctionIR.qll",
19+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/FunctionIR.qll",
20+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/FunctionIR.qll"
2121
],
2222
"C++ IR OperandTag": [
23-
"cpp/ql/src/semmle/code/cpp/ir/internal/OperandTag.qll",
24-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/OperandTag.qll",
25-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/OperandTag.qll"
23+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/OperandTag.qll",
24+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/OperandTag.qll",
25+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/OperandTag.qll"
2626
],
2727
"C++ IR IRImpl": [
28-
"cpp/ql/src/semmle/code/cpp/ir/internal/IRImpl.qll",
29-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/IRImpl.qll",
30-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/IRImpl.qll"
28+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IR.qll",
29+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IR.qll",
30+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IR.qll"
3131
],
3232
"C++ IR IRSanityImpl": [
33-
"cpp/ql/src/semmle/code/cpp/ir/internal/IRSanityImpl.qll",
34-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/IRSanityImpl.qll",
35-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/IRSanityImpl.qll"
33+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRSanity.qll",
34+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRSanity.qll",
35+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRSanity.qll"
3636
],
3737
"C++ IR PrintIRImpl": [
38-
"cpp/ql/src/semmle/code/cpp/ir/internal/PrintIRImpl.qll",
39-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/PrintIRImpl.qll",
40-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/PrintIRImpl.qll"
38+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/PrintIR.qll",
39+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll",
40+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll"
4141
],
4242
"C++ SSA AliasAnalysis": [
43-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/AliasAnalysis.qll",
44-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/AliasAnalysis.qll"
43+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll",
44+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll"
4545
],
4646
"C++ SSA SimpleSSA": [
47-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/SimpleSSA.qll",
48-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/SimpleSSA.qll"
47+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SimpleSSA.qll",
48+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SimpleSSA.qll"
4949
],
5050
"C++ SSA IRBlockConstruction": [
51-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/IRBlockConstruction.qll",
52-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/IRBlockConstruction.qll"
51+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRBlockConstruction.qll",
52+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/IRBlockConstruction.qll"
5353
],
5454
"C++ SSA SSAConstruction": [
55-
"cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/SSAConstruction.qll",
56-
"cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/SSAConstruction.qll"
55+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll",
56+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll"
5757
]
5858
}

cpp/ql/src/Critical/MemoryMayNotBeFreed.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode
6262
// a realloc followed by a null check at 'node' (return the non-null
6363
// successor, i.e. where the realloc is confirmed to have succeeded)
6464
newV.getAnAssignedValue() = reallocCall and
65-
node.(AnalysedExpr).getNonNullSuccessor(newV) = verified
65+
node.(AnalysedExpr).getNonNullSuccessor(newV) = verified and
6666
// note: this case uses naive flow logic (getAnAssignedValue).
67+
68+
// special case: if the result of the 'realloc' is assigned to the
69+
// same variable, we don't descriminate properly between the old
70+
// and the new allocation; better to not consider this a free at
71+
// all in that case.
72+
newV != v
6773
) or (
6874
// a realloc(ptr, 0), which always succeeds and frees
6975
// (return the realloc itself)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class Class extends UserType {
566566
* The alignment of this type in bytes (on the machine where facts were
567567
* extracted).
568568
*/
569-
int getAlignment() { usertypesize(underlyingElement(this),_,result) }
569+
override int getAlignment() { usertypesize(underlyingElement(this),_,result) }
570570

571571
/**
572572
* Holds if this class is constructed from another class as a result of

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ abstract class Container extends Locatable, @container {
162162
*
163163
* This is the absolute path of the container.
164164
*/
165-
string toString() {
165+
override string toString() {
166166
result = getAbsolutePath()
167167
}
168168
}

cpp/ql/src/semmle/code/cpp/controlflow/internal/PrimitiveBasicBlocks.qll

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,28 @@ private cached module Cached {
4343
(not successors_extended(_, node) and successors_extended(node, _))
4444
}
4545

46+
/** Holds if `n2` follows `n1` in a `PrimitiveBasicBlock`. */
47+
private predicate member_step(Node n1, Node n2) {
48+
successors_extended(n1, n2) and
49+
not n2 instanceof PrimitiveBasicBlock
50+
}
51+
52+
/** Returns the index of `node` in its `PrimitiveBasicBlock`. */
53+
private int getMemberIndex(Node node) {
54+
primitive_basic_block_entry_node(node) and
55+
result = 0
56+
or
57+
exists(Node prev |
58+
member_step(prev, node) and
59+
result = getMemberIndex(prev) + 1
60+
)
61+
}
62+
4663
/** Holds if `node` is the `pos`th control-flow node in primitive basic block `bb`. */
4764
cached
4865
predicate primitive_basic_block_member(Node node, PrimitiveBasicBlock bb, int pos) {
49-
(node = bb and pos = 0)
50-
or
51-
(not (node instanceof PrimitiveBasicBlock) and
52-
exists (Node pred
53-
| successors_extended(pred, node)
54-
| primitive_basic_block_member(pred, bb, pos - 1)))
66+
pos = getMemberIndex(node) and
67+
member_step*(bb, node)
5568
}
5669

5770
/** Gets the number of control-flow nodes in the primitive basic block `bb`. */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ predicate readStep(Node node1, Content f, Node node2) {
128128
* numeric conversions, and otherwise the erasure is used.
129129
*/
130130
RefType getErasedRepr(Type t) {
131+
suppressUnusedType(t) and
131132
result instanceof VoidType // stub implementation
132133
}
133134

@@ -140,6 +141,8 @@ predicate compatibleTypes(Type t1, Type t2) {
140141
any() // stub implementation
141142
}
142143

144+
private predicate suppressUnusedType(Type t) { any() }
145+
143146
//////////////////////////////////////////////////////////////////////////////
144147
// Java QL library compatibility wrappers
145148
//////////////////////////////////////////////////////////////////////////////
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
import internal.IRImpl
1+
// Most queries should operate on the aliased SSA IR, so that's what we expose
2+
// publically as the "IR".
3+
import implementation.aliased_ssa.IR

cpp/ql/src/semmle/code/cpp/ir/IRSanity.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @id cpp/ir-sanity-check
66
*/
77

8-
import internal.IRSanityImpl
8+
import implementation.aliased_ssa.IRSanity

0 commit comments

Comments
 (0)