Skip to content

Commit bed6d2b

Browse files
author
Robert Marsh
committed
Merge branch 'master' into rdmarsh/cpp/malloc-alias-locations
2 parents 9e1ea01 + de66841 commit bed6d2b

File tree

421 files changed

+22581
-14544
lines changed

Some content is hidden

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

421 files changed

+22581
-14544
lines changed

.codeqlmanifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
"*/ql/test/qlpack.yml",
33
"*/upgrades/qlpack.yml",
44
"misc/legacy-support/*/qlpack.yml",
5-
"misc/suite-helpers/qlpack.yml",
6-
"codeql/.codeqlmanifest.json" ] }
5+
"misc/suite-helpers/qlpack.yml" ] }

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# editor and OS artifacts
22
*~
33
.DS_STORE
4+
*.swp
45

56
# query compilation caches
67
.cache

change-notes/1.24/analysis-cpp.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
1919
| Memory is never freed (`cpp/memory-never-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2020
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2121
| Missing return statement (`cpp/missing-return`) | Fewer false positive results | Functions containing `asm` statements are no longer highlighted by this query. |
22+
| No space for zero terminator (`cpp/no-space-for-terminator`) | More correct results | String arguments to formatting functions are now (usually) expected to be null terminated strings. |
2223
| Hard-coded Japanese era start date (`cpp/japanese-era/exact-era-date`) | | This query is no longer run on LGTM. |
2324
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | This query has been modified to be more conservative when identifying which pointers point to null-terminated strings. This approach produces fewer, more accurate results. |
2425
| Overloaded assignment does not return 'this' (`cpp/assignment-does-not-return-this`) | Fewer false positive results | This query no longer reports incorrect results in template classes. |
2526
| Unsafe array for days of the year (`cpp/leap-year/unsafe-array-for-days-of-the-year`) | | This query is no longer run on LGTM. |
2627

2728
## Changes to libraries
2829

29-
* The data-flow library has been improved when flow through functions needs to be
30-
combined with both taint tracking and flow through fields allowing more flow
31-
to be tracked. This affects and improves some security queries, which may
32-
report additional results.
30+
* The data-flow library has been improved, which affects and improves some security queries. The improvements are:
31+
- Track flow through functions that combine taint tracking with flow through fields.
32+
- Track flow through clone-like functions, that is, functions that read contents of a field from a
33+
parameter and stores the value in the field of a returned object.
3334
* Created the `semmle.code.cpp.models.interfaces.Allocation` library to model allocation such as `new` expressions and calls to `malloc`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3435
* Created the `semmle.code.cpp.models.interfaces.Deallocation` library to model deallocation such as `delete` expressions and calls to `free`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3536
* The new class `StackVariable` should be used in place of `LocalScopeVariable`

change-notes/1.24/analysis-csharp.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ The following changes in version 1.24 affect C# analysis in all applications.
2727
## Changes to code extraction
2828

2929
* Tuple expressions, for example `(int,bool)` in `default((int,bool))` are now extracted correctly.
30-
* Expression nullability flow state is extracted.
30+
* Expression nullability flow state is extracted.
31+
* Implicitly typed `stackalloc` expressions are now extracted correctly.
32+
* The difference between `stackalloc` array creations and normal array creations is extracted.
3133

3234
## Changes to libraries
3335

34-
* The data-flow library has been improved when flow through methods needs to be
35-
combined with both taint tracking and flow through fields allowing more flow
36-
to be tracked. This affects and improves most security queries, which may
37-
report additional results.
36+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
37+
- Track flow through methods that combine taint tracking with flow through fields.
38+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
39+
parameter and stores the value in the field of a returned object.
3840
* The taint tracking library now tracks flow through (implicit or explicit) conversion operator calls.
3941
* [Code contracts](https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts) are now recognized, and are treated like any other assertion methods.
4042
* Expression nullability flow state is given by the predicates `Expr.hasNotNullFlowState()` and `Expr.hasMaybeNullFlowState()`.
43+
* `stackalloc` array creations are now represented by the QL class `Stackalloc`. Previously they were represented by the class `ArrayCreation`.
4144

4245
## Changes to autobuilder

change-notes/1.24/analysis-java.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ The following changes in version 1.24 affect Java analysis in all applications.
2626

2727
## Changes to libraries
2828

29-
* The data-flow library has been improved when flow through methods needs to be
30-
combined with both taint tracking and flow through fields allowing more flow
31-
to be tracked. This affects and improves most security queries, which may
32-
report additional results.
29+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
30+
- Track flow through methods that combine taint tracking with flow through fields.
31+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
32+
parameter and stores the value in the field of a returned object.
3333
* Identification of test classes has been improved. Previously, one of the
3434
match conditions would classify any class with a name containing the string
3535
"Test" as a test class, but now this matching has been replaced with one that

change-notes/1.24/analysis-javascript.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@
99

1010
* Imports that rely on path-mappings from a `tsconfig.json` file can now be resolved.
1111

12+
* Export declarations of the form `export * as ns from "x"` are now analyzed more precisely.
13+
1214
* The analysis of sanitizer guards has improved, leading to fewer false-positive results from the security queries.
1315

1416
* Support for the following frameworks and libraries has been improved:
15-
- [react](https://www.npmjs.com/package/react)
16-
- [typeahead.js](https://www.npmjs.com/package/typeahead.js)
17-
- [Handlebars](https://www.npmjs.com/package/handlebars)
1817
- [Electron](https://electronjs.org/)
18+
- [Handlebars](https://www.npmjs.com/package/handlebars)
19+
- [Koa](https://www.npmjs.com/package/koa)
1920
- [Node.js](https://nodejs.org/)
2021
- [Socket.IO](https://socket.io/)
21-
- [ws](https://github.com/websockets/ws)
2222
- [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
23-
- [Koa](https://www.npmjs.com/package/koa)
24-
- [lazy-cache](https://www.npmjs.com/package/lazy-cache)
23+
- [chrome-remote-interface](https://www.npmjs.com/package/chrome-remote-interface)
2524
- [for-in](https://www.npmjs.com/package/for-in)
2625
- [for-own](https://www.npmjs.com/package/for-own)
26+
- [http2](https://nodejs.org/api/http2.html)
27+
- [lazy-cache](https://www.npmjs.com/package/lazy-cache)
28+
- [react](https://www.npmjs.com/package/react)
29+
- [send](https://www.npmjs.com/package/send)
30+
- [typeahead.js](https://www.npmjs.com/package/typeahead.js)
31+
- [ws](https://github.com/websockets/ws)
2732

2833
## New queries
2934

@@ -33,6 +38,7 @@
3338
| Regular expression always matches (`js/regex/always-matches`) | correctness, regular-expressions | Highlights regular expression checks that trivially succeed by matching an empty substring. Results are shown on LGTM by default. |
3439
| Missing await (`js/missing-await`) | correctness | Highlights expressions that operate directly on a promise object in a nonsensical way, instead of awaiting its result. Results are shown on LGTM by default. |
3540
| Prototype pollution in utility function (`js/prototype-pollution-utility`) | security, external/cwe/cwe-400, external/cwe/cwe-471 | Highlights recursive copying operations that are susceptible to prototype pollution. Results are shown on LGTM by default. |
41+
| Unsafe jQuery plugin (`js/unsafe-jquery-plugin`) | Highlights potential XSS vulnerabilities in unsafely designed jQuery plugins. Results are shown on LGTM by default. |
3642

3743
## Changes to existing queries
3844

@@ -46,6 +52,7 @@
4652
| Use of call stack introspection in strict mode (`js/strict-mode-call-stack-introspection`) | Fewer false positive results | The query no longer flags expression statements. |
4753
| Missing CSRF middleware (`js/missing-token-validation`) | Fewer false positive results | The query reports fewer duplicates and only flags handlers that explicitly access cookie data. |
4854
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed. |
55+
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional ways of constructing arguments to `cmd.exe` and `/bin/sh`. |
4956

5057
## Changes to libraries
5158

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Improvements to Python analysis
2+
3+
The following changes in version 1.24 affect Python analysis in all applications.
4+
5+
## General improvements
6+
7+
## New queries
8+
9+
| **Query** | **Tags** | **Purpose** |
10+
|-----------------------------|-----------|--------------------------------------------------------------------|
11+
12+
## Changes to existing queries
13+
14+
| **Query** | **Expected impact** | **Change** |
15+
|----------------------------|------------------------|------------------------------------------------------------------|
16+
17+
### Web framework support
18+
19+
The QL-library support for the web frameworks Bottle, CherryPy, Falcon, Pyramid, TurboGears, Tornado, and Twisted have
20+
been fixed so they provide a proper HttpRequestTaintSource, instead of a TaintSource. This will enable results for the following queries:
21+
22+
- py/path-injection
23+
- py/command-line-injection
24+
- py/reflective-xss
25+
- py/sql-injection
26+
- py/code-injection
27+
- py/unsafe-deserialization
28+
- py/url-redirection
29+
30+
The QL-library support for the web framework Twisted have been fixed so they provide a proper
31+
HttpResponseTaintSink, instead of a TaintSink. This will enable results for the following
32+
queries:
33+
34+
- py/reflective-xss
35+
- py/stack-trace-exposure
36+
37+
## Changes to libraries

config/identical-files.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@
222222
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintSSA.qll",
223223
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/PrintSSA.qll"
224224
],
225-
"C++ IR ValueNumberInternal": [
225+
"IR ValueNumberInternal": [
226226
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/internal/ValueNumberingInternal.qll",
227227
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingInternal.qll",
228-
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/internal/ValueNumberingInternal.qll"
228+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/internal/ValueNumberingInternal.qll",
229+
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/gvn/internal/ValueNumberingInternal.qll",
230+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingInternal.qll"
229231
],
230232
"C++ IR ValueNumber": [
231233
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll",

cpp/ql/src/Security/CWE/CWE-131/NoSpaceForZeroTerminator.ql

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,25 @@ import semmle.code.cpp.models.interfaces.Allocation
2222
predicate terminationProblem(AllocationExpr malloc, string msg) {
2323
// malloc(strlen(...))
2424
exists(StrlenCall strlen | DataFlow::localExprFlow(strlen, malloc.getSizeExpr())) and
25-
// flows into a null-terminated string function
25+
// flows to a call that implies this is a null-terminated string
2626
exists(ArrayFunction af, FunctionCall fc, int arg |
2727
DataFlow::localExprFlow(malloc, fc.getArgument(arg)) and
2828
fc.getTarget() = af and
2929
(
30-
// null terminated string
30+
// flows into null terminated string argument
3131
af.hasArrayWithNullTerminator(arg)
3232
or
33-
// likely a null terminated string (such as `strcpy`, `strcat`)
33+
// flows into likely null terminated string argument (such as `strcpy`, `strcat`)
3434
af.hasArrayWithUnknownSize(arg)
35+
or
36+
// flows into string argument to a formatting function (such as `printf`)
37+
exists(int n, FormatLiteral fl |
38+
fc.getArgument(arg) = fc.(FormattingFunctionCall).getConversionArgument(n) and
39+
fl = fc.(FormattingFunctionCall).getFormat() and
40+
fl.getConversionType(n) instanceof PointerType and // `%s`, `%ws` etc
41+
not fl.getConversionType(n) instanceof VoidPointerType and // exclude: `%p`
42+
not fl.hasPrecision(n) // exclude: `%.*s`
43+
)
3544
)
3645
) and
3746
msg = "This allocation does not include space to null-terminate the string."

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
139139
/** Gets a parameter of this function. */
140140
Parameter getAParameter() { params(unresolveElement(result), underlyingElement(this), _, _) }
141141

142+
/**
143+
* Gets an access of this function.
144+
*
145+
* To get calls to this function, use `getACallToThisFunction` instead.
146+
*/
147+
FunctionAccess getAnAccess() { result.getTarget() = this }
148+
142149
/**
143150
* Gets the number of parameters of this function, _not_ including any
144151
* implicit `this` parameter or any `...` varargs pseudo-parameter.
@@ -174,6 +181,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
174181
result = getParameter(index).getTypedName() + ", " + getParameterStringFrom(index + 1)
175182
}
176183

184+
/** Gets a call to this function. */
177185
FunctionCall getACallToThisFunction() { result.getTarget() = this }
178186

179187
/**

0 commit comments

Comments
 (0)