Skip to content

Commit 80f4131

Browse files
authored
Merge branch 'master' into shelljs
2 parents d594e55 + f7dda1b commit 80f4131

File tree

45 files changed

+630
-394
lines changed

Some content is hidden

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

45 files changed

+630
-394
lines changed

change-notes/1.21/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| Memory is never freed (`cpp/memory-never-freed`) | More correct results | Support added for more Microsoft-specific allocation functions, including `LocalAlloc`, `GlobalAlloc`, `HeapAlloc` and `CoTaskMemAlloc`. |
1919
| Resource not released in destructor (`cpp/resource-not-released-in-destructor`) | Fewer false positive results | Resource allocation and deallocation functions are now determined more accurately. |
2020
| Comparison result is always the same | Fewer false positive results | The range analysis library is now more conservative about floating point values being possibly `NaN` |
21+
| Use of potentially dangerous function | More correct results | Calls to `localtime`, `ctime` and `asctime` are now detected by this query. |
2122
| Wrong type of arguments to formatting function (`cpp/wrong-type-format-argument`) | More correct results and fewer false positive results | This query now more accurately identifies wide and non-wide string/character format arguments on different platforms. Platform detection has also been made more accurate for the purposes of this query. |
2223
| Wrong type of arguments to formatting function (`cpp/wrong-type-format-argument`) | Fewer false positive results | Non-standard uses of %L are now understood. |
2324

change-notes/1.21/analysis-csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
| **Query** | **Expected impact** | **Change** |
66
|------------------------------|------------------------|-----------------------------------|
7-
7+
| Class defines a field that uses an ICryptoTransform class in a way that would be unsafe for concurrent threads (`cs/thread-unsafe-icryptotransform-field-in-class`) | Fewer false positive results | The criteria for a result has changed to include nested properties, nested fields and collections. The format of the alert message has changed to highlight the static field. |
88

99
## Changes to code extraction
1010

change-notes/1.21/analysis-java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| **Query** | **Expected impact** | **Change** |
1111
|----------------------------|------------------------|------------------------------------------------------------------|
12+
| Implicit conversion from array to string (`java/print-array`) | Fewer false positive results | Results in slf4j logging calls are no longer reported as slf4j supports array printing. |
1213

1314
## Changes to QL libraries
1415

change-notes/1.21/analysis-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* Support for the following frameworks and libraries has been improved:
66
- [koa](https://github.com/koajs/koa)
77
- [socket.io](http://socket.io)
8+
- [Node.js](http://nodejs.org)
89
- [Firebase](https://firebase.google.com/)
10+
- [Express](https://expressjs.com/)
911
- [shelljs](https://www.npmjs.com/package/shelljs)
1012

1113
* The security queries now track data flow through Base64 decoders such as the Node.js `Buffer` class, the DOM function `atob`, and a number of npm packages intcluding [`abab`](https://www.npmjs.com/package/abab), [`atob`](https://www.npmjs.com/package/atob), [`btoa`](https://www.npmjs.com/package/btoa), [`base-64`](https://www.npmjs.com/package/base-64), [`js-base64`](https://www.npmjs.com/package/js-base64), [`Base64.js`](https://www.npmjs.com/package/Base64) and [`base64-js`](https://www.npmjs.com/package/base64-js).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Improvements to Python analysis
2+
3+
4+
## General improvements
5+
6+
> Changes that affect alerts in many files or from many queries
7+
> For example, changes to file classification
8+
9+
## New queries
10+
| **Query** | **Tags** | **Purpose** |
11+
|-----------|----------|-------------|
12+
| Accepting unknown SSH host keys when using Paramiko (`py/paramiko-missing-host-key-validation`) | security, external/cwe/cwe-295 | Finds instances where Paramiko is configured to accept unknown host keys. Results are shown on LGTM by default. |
13+
14+
15+
## Changes to existing queries
16+
17+
| **Query** | **Expected impact** | **Change** |
18+
|-----------|---------------------|------------|
19+
20+
## Changes to code extraction
21+
22+
* *Series of bullet points*
23+
24+
## Changes to QL libraries
25+
26+
* *Series of bullet points*

cpp/ql/src/Best Practices/SloppyGlobal.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @name Short global name
33
* @description Global variables should have descriptive names, to help document their use, avoid namespace pollution and reduce the risk of shadowing with local variables.
44
* @kind problem
5-
* @problem.severity warning
6-
* @precision high
5+
* @problem.severity recommendation
6+
* @precision very-high
77
* @id cpp/short-global-name
88
* @tags maintainability
99
*/

cpp/ql/src/Security/CWE/CWE-468/IncorrectPointerScaling.ql

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -9,111 +9,8 @@
99
* @tags security
1010
* external/cwe/cwe-468
1111
*/
12-
import cpp
13-
import semmle.code.cpp.controlflow.SSA
1412
import IncorrectPointerScalingCommon
1513

16-
private predicate isPointerType(Type t) {
17-
t instanceof PointerType or
18-
t instanceof ArrayType
19-
}
20-
21-
private Type baseType(Type t) {
22-
(
23-
exists (PointerType dt
24-
| dt = t.getUnspecifiedType() and
25-
result = dt.getBaseType().getUnspecifiedType()) or
26-
exists (ArrayType at
27-
| at = t.getUnspecifiedType() and
28-
(not at.getBaseType().getUnspecifiedType() instanceof ArrayType) and
29-
result = at.getBaseType().getUnspecifiedType()) or
30-
exists (ArrayType at, ArrayType at2
31-
| at = t.getUnspecifiedType() and
32-
at2 = at.getBaseType().getUnspecifiedType() and
33-
result = baseType(at2))
34-
)
35-
// Make sure that the type has a size and that it isn't ambiguous.
36-
and strictcount(result.getSize()) = 1
37-
}
38-
39-
/**
40-
* Holds if there is a pointer expression with type `sourceType` at
41-
* location `sourceLoc` which might be the source expression for `use`.
42-
*
43-
* For example, with
44-
* ```
45-
* int intArray[5] = { 1, 2, 3, 4, 5 };
46-
* char *charPointer = (char *)intArray;
47-
* return *(charPointer + i);
48-
* ```
49-
* the array initializer on the first line is a source expression
50-
* for the use of `charPointer` on the third line.
51-
*
52-
* The source will either be an `Expr` or a `Parameter`.
53-
*/
54-
private
55-
predicate exprSourceType(Expr use, Type sourceType, Location sourceLoc) {
56-
// Reaching definitions.
57-
if exists (SsaDefinition def, LocalScopeVariable v | use = def.getAUse(v)) then
58-
exists (SsaDefinition def, LocalScopeVariable v
59-
| use = def.getAUse(v)
60-
| defSourceType(def, v, sourceType, sourceLoc))
61-
62-
// Pointer arithmetic
63-
else if use instanceof PointerAddExpr then
64-
exprSourceType(use.(PointerAddExpr).getLeftOperand(), sourceType, sourceLoc)
65-
else if use instanceof PointerSubExpr then
66-
exprSourceType(use.(PointerSubExpr).getLeftOperand(), sourceType, sourceLoc)
67-
else if use instanceof AddExpr then
68-
exprSourceType(use.(AddExpr).getAnOperand(), sourceType, sourceLoc)
69-
else if use instanceof SubExpr then
70-
exprSourceType(use.(SubExpr).getAnOperand(), sourceType, sourceLoc)
71-
else if use instanceof CrementOperation then
72-
exprSourceType(use.(CrementOperation).getOperand(), sourceType, sourceLoc)
73-
74-
// Conversions are not in the AST, so ignore them.
75-
else if use instanceof Conversion then
76-
none()
77-
78-
// Source expressions
79-
else
80-
(sourceType = use.getType().getUnspecifiedType() and
81-
isPointerType(sourceType) and
82-
sourceLoc = use.getLocation())
83-
}
84-
85-
/**
86-
* Holds if there is a pointer expression with type `sourceType` at
87-
* location `sourceLoc` which might define the value of `v` at `def`.
88-
*/
89-
private
90-
predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
91-
Type sourceType, Location sourceLoc) {
92-
exprSourceType(def.getDefiningValue(v), sourceType, sourceLoc)
93-
or
94-
defSourceType(def.getAPhiInput(v), v, sourceType, sourceLoc)
95-
or
96-
exists (Parameter p
97-
| p = v and
98-
def.definedByParameter(p) and
99-
sourceType = p.getType().getUnspecifiedType() and
100-
strictcount(p.getType()) = 1 and
101-
isPointerType(sourceType) and
102-
sourceLoc = p.getLocation())
103-
}
104-
105-
/**
106-
* Gets the pointer arithmetic expression that `e` is (directly) used
107-
* in, if any.
108-
*
109-
* For example, in `(char*)(p + 1)`, for `p`, ths result is `p + 1`.
110-
*/
111-
private Expr pointerArithmeticParent(Expr e) {
112-
e = result.(PointerAddExpr).getLeftOperand() or
113-
e = result.(PointerSubExpr).getLeftOperand() or
114-
e = result.(PointerDiffExpr).getAnOperand()
115-
}
116-
11714
from Expr dest, Type destType, Type sourceType, Type sourceBase,
11815
Type destBase, Location sourceLoc
11916
where exists(pointerArithmeticParent(dest))

cpp/ql/src/Security/CWE/CWE-468/IncorrectPointerScalingChar.ql

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,103 +9,8 @@
99
* @tags security
1010
* external/cwe/cwe-468
1111
*/
12-
import cpp
13-
import semmle.code.cpp.controlflow.SSA
1412
import IncorrectPointerScalingCommon
1513

16-
private predicate isPointerType(Type t) {
17-
t instanceof PointerType or
18-
t instanceof ArrayType
19-
}
20-
21-
private Type baseType(Type t) {
22-
exists (DerivedType dt
23-
| dt = t.getUnspecifiedType() and
24-
isPointerType(dt) and
25-
result = dt.getBaseType().getUnspecifiedType())
26-
27-
// Make sure that the type has a size and that it isn't ambiguous.
28-
and strictcount(result.getSize()) = 1
29-
}
30-
31-
/**
32-
* Holds if there is a pointer expression with type `sourceType` at
33-
* location `sourceLoc` which might be the source expression for `use`.
34-
*
35-
* For example, with
36-
* ```
37-
* int intArray[5] = { 1, 2, 3, 4, 5 };
38-
* char *charPointer = (char *)intArray;
39-
* return *(charPointer + i);
40-
* ```
41-
* the array initializer on the first line is a source expression
42-
* for the use of `charPointer` on the third line.
43-
*
44-
* The source will either be an `Expr` or a `Parameter`.
45-
*/
46-
private
47-
predicate exprSourceType(Expr use, Type sourceType, Location sourceLoc) {
48-
// Reaching definitions.
49-
if exists (SsaDefinition def, LocalScopeVariable v | use = def.getAUse(v)) then
50-
exists (SsaDefinition def, LocalScopeVariable v
51-
| use = def.getAUse(v)
52-
| defSourceType(def, v, sourceType, sourceLoc))
53-
54-
// Pointer arithmetic
55-
else if use instanceof PointerAddExpr then
56-
exprSourceType(use.(PointerAddExpr).getLeftOperand(), sourceType, sourceLoc)
57-
else if use instanceof PointerSubExpr then
58-
exprSourceType(use.(PointerSubExpr).getLeftOperand(), sourceType, sourceLoc)
59-
else if use instanceof AddExpr then
60-
exprSourceType(use.(AddExpr).getAnOperand(), sourceType, sourceLoc)
61-
else if use instanceof SubExpr then
62-
exprSourceType(use.(SubExpr).getAnOperand(), sourceType, sourceLoc)
63-
else if use instanceof CrementOperation then
64-
exprSourceType(use.(CrementOperation).getOperand(), sourceType, sourceLoc)
65-
66-
// Conversions are not in the AST, so ignore them.
67-
else if use instanceof Conversion then
68-
none()
69-
70-
// Source expressions
71-
else
72-
(sourceType = use.getType().getUnspecifiedType() and
73-
isPointerType(sourceType) and
74-
sourceLoc = use.getLocation())
75-
}
76-
77-
/**
78-
* Holds if there is a pointer expression with type `sourceType` at
79-
* location `sourceLoc` which might define the value of `v` at `def`.
80-
*/
81-
private
82-
predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
83-
Type sourceType, Location sourceLoc) {
84-
exprSourceType(def.getDefiningValue(v), sourceType, sourceLoc)
85-
or
86-
defSourceType(def.getAPhiInput(v), v, sourceType, sourceLoc)
87-
or
88-
exists (Parameter p
89-
| p = v and
90-
def.definedByParameter(p) and
91-
sourceType = p.getType().getUnspecifiedType() and
92-
strictcount(p.getType()) = 1 and
93-
isPointerType(sourceType) and
94-
sourceLoc = p.getLocation())
95-
}
96-
97-
/**
98-
* Gets the pointer arithmetic expression that `e` is (directly) used
99-
* in, if any.
100-
*
101-
* For example, in `(char*)(p + 1)`, for `p`, ths result is `p + 1`.
102-
*/
103-
private Expr pointerArithmeticParent(Expr e) {
104-
e = result.(PointerAddExpr).getLeftOperand() or
105-
e = result.(PointerSubExpr).getLeftOperand() or
106-
e = result.(PointerDiffExpr).getAnOperand()
107-
}
108-
10914
from Expr dest, Type destType, Type sourceType, Type sourceBase,
11015
Type destBase, Location sourceLoc
11116
where exists(pointerArithmeticParent(dest))

cpp/ql/src/Security/CWE/CWE-468/IncorrectPointerScalingCommon.qll

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,109 @@ predicate addWithSizeof(Expr e, Expr sizeofExpr, Type sizeofParam) {
4646
| e = subExpr.getLeftOperand() and
4747
multiplyWithSizeof(subExpr.getRightOperand(), sizeofExpr, sizeofParam))
4848
}
49+
50+
/**
51+
* Holds if `t` is a pointer or array type.
52+
*/
53+
predicate isPointerType(Type t) {
54+
t instanceof PointerType or
55+
t instanceof ArrayType
56+
}
57+
58+
/**
59+
* Gets the base type of a pointer or array type. In the case of an array of
60+
* arrays, the inner base type is returned.
61+
*/
62+
Type baseType(Type t) {
63+
(
64+
exists (PointerType dt
65+
| dt = t.getUnspecifiedType() and
66+
result = dt.getBaseType().getUnspecifiedType()) or
67+
exists (ArrayType at
68+
| at = t.getUnspecifiedType() and
69+
(not at.getBaseType().getUnspecifiedType() instanceof ArrayType) and
70+
result = at.getBaseType().getUnspecifiedType()) or
71+
exists (ArrayType at, ArrayType at2
72+
| at = t.getUnspecifiedType() and
73+
at2 = at.getBaseType().getUnspecifiedType() and
74+
result = baseType(at2))
75+
)
76+
// Make sure that the type has a size and that it isn't ambiguous.
77+
and strictcount(result.getSize()) = 1
78+
}
79+
80+
/**
81+
* Holds if there is a pointer expression with type `sourceType` at
82+
* location `sourceLoc` which might be the source expression for `use`.
83+
*
84+
* For example, with
85+
* ```
86+
* int intArray[5] = { 1, 2, 3, 4, 5 };
87+
* char *charPointer = (char *)intArray;
88+
* return *(charPointer + i);
89+
* ```
90+
* the array initializer on the first line is a source expression
91+
* for the use of `charPointer` on the third line.
92+
*
93+
* The source will either be an `Expr` or a `Parameter`.
94+
*/
95+
predicate exprSourceType(Expr use, Type sourceType, Location sourceLoc) {
96+
// Reaching definitions.
97+
if exists (SsaDefinition def, LocalScopeVariable v | use = def.getAUse(v)) then
98+
exists (SsaDefinition def, LocalScopeVariable v
99+
| use = def.getAUse(v)
100+
| defSourceType(def, v, sourceType, sourceLoc))
101+
102+
// Pointer arithmetic
103+
else if use instanceof PointerAddExpr then
104+
exprSourceType(use.(PointerAddExpr).getLeftOperand(), sourceType, sourceLoc)
105+
else if use instanceof PointerSubExpr then
106+
exprSourceType(use.(PointerSubExpr).getLeftOperand(), sourceType, sourceLoc)
107+
else if use instanceof AddExpr then
108+
exprSourceType(use.(AddExpr).getAnOperand(), sourceType, sourceLoc)
109+
else if use instanceof SubExpr then
110+
exprSourceType(use.(SubExpr).getAnOperand(), sourceType, sourceLoc)
111+
else if use instanceof CrementOperation then
112+
exprSourceType(use.(CrementOperation).getOperand(), sourceType, sourceLoc)
113+
114+
// Conversions are not in the AST, so ignore them.
115+
else if use instanceof Conversion then
116+
none()
117+
118+
// Source expressions
119+
else
120+
(sourceType = use.getType().getUnspecifiedType() and
121+
isPointerType(sourceType) and
122+
sourceLoc = use.getLocation())
123+
}
124+
125+
/**
126+
* Holds if there is a pointer expression with type `sourceType` at
127+
* location `sourceLoc` which might define the value of `v` at `def`.
128+
*/
129+
predicate defSourceType(SsaDefinition def, LocalScopeVariable v,
130+
Type sourceType, Location sourceLoc) {
131+
exprSourceType(def.getDefiningValue(v), sourceType, sourceLoc)
132+
or
133+
defSourceType(def.getAPhiInput(v), v, sourceType, sourceLoc)
134+
or
135+
exists (Parameter p
136+
| p = v and
137+
def.definedByParameter(p) and
138+
sourceType = p.getType().getUnspecifiedType() and
139+
strictcount(p.getType()) = 1 and
140+
isPointerType(sourceType) and
141+
sourceLoc = p.getLocation())
142+
}
143+
144+
/**
145+
* Gets the pointer arithmetic expression that `e` is (directly) used
146+
* in, if any.
147+
*
148+
* For example, in `(char*)(p + 1)`, for `p`, ths result is `p + 1`.
149+
*/
150+
Expr pointerArithmeticParent(Expr e) {
151+
e = result.(PointerAddExpr).getLeftOperand() or
152+
e = result.(PointerSubExpr).getLeftOperand() or
153+
e = result.(PointerDiffExpr).getAnOperand()
154+
}

0 commit comments

Comments
 (0)