Skip to content

Commit a4c1a62

Browse files
committed
Merge branch 'main' of https://github.com/github/codeql into python/add-comprehension-capture-flow
2 parents 977767b + 306b087 commit a4c1a62

File tree

733 files changed

+11363
-5092
lines changed

Some content is hidden

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

733 files changed

+11363
-5092
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ use_repo(
128128
"kotlin-compiler-1.9.20-Beta",
129129
"kotlin-compiler-2.0.0-RC1",
130130
"kotlin-compiler-2.0.20-Beta2",
131+
"kotlin-compiler-2.1.0-Beta1",
131132
"kotlin-compiler-embeddable-1.5.0",
132133
"kotlin-compiler-embeddable-1.5.10",
133134
"kotlin-compiler-embeddable-1.5.20",
@@ -141,6 +142,7 @@ use_repo(
141142
"kotlin-compiler-embeddable-1.9.20-Beta",
142143
"kotlin-compiler-embeddable-2.0.0-RC1",
143144
"kotlin-compiler-embeddable-2.0.20-Beta2",
145+
"kotlin-compiler-embeddable-2.1.0-Beta1",
144146
"kotlin-stdlib-1.5.0",
145147
"kotlin-stdlib-1.5.10",
146148
"kotlin-stdlib-1.5.20",
@@ -154,6 +156,7 @@ use_repo(
154156
"kotlin-stdlib-1.9.20-Beta",
155157
"kotlin-stdlib-2.0.0-RC1",
156158
"kotlin-stdlib-2.0.20-Beta2",
159+
"kotlin-stdlib-2.1.0-Beta1",
157160
)
158161

159162
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")

config/identical-files.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@
5757
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll",
5858
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll"
5959
],
60-
"Model as Data Generation Java/C# - CaptureModels": [
61-
"java/ql/src/utils/modelgenerator/internal/CaptureModels.qll",
62-
"csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll"
63-
],
6460
"Sign Java/C#": [
6561
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/Sign.qll",
6662
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/Sign.qll"
@@ -355,5 +351,9 @@
355351
"Python model summaries test extension": [
356352
"python/ql/test/library-tests/dataflow/model-summaries/InlineTaintTest.ext.yml",
357353
"python/ql/test/library-tests/dataflow/model-summaries/NormalDataflowTest.ext.yml"
354+
],
355+
"Diagnostics.qll": [
356+
"ruby/ql/lib/codeql/ruby/Diagnostics.qll",
357+
"rust/ql/lib/codeql/rust/Diagnostics.qll"
358358
]
359359
}

cpp/ql/lib/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
No user-facing changes.
4+
15
## 2.0.0
26

37
### Breaking Changes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 2.0.1
2+
3+
No user-facing changes.

cpp/ql/lib/codeql-pack.release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 2.0.0
2+
lastReleaseVersion: 2.0.1

cpp/ql/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-all
2-
version: 2.0.1-dev
2+
version: 2.0.2-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
500500
* Gets the nearest enclosing AccessHolder.
501501
*/
502502
override AccessHolder getEnclosingAccessHolder() { result = this.getDeclaringType() }
503+
504+
/**
505+
* Holds if this function has extraction errors that create an `ErrorExpr`.
506+
*/
507+
predicate hasErrors() {
508+
exists(ErrorExpr e |
509+
e.getEnclosingFunction() = this and
510+
// Exclude the first allocator call argument because it is always extracted as `ErrorExpr`.
511+
not exists(NewOrNewArrayExpr new | e = new.getAllocatorCall().getArgument(0))
512+
)
513+
}
503514
}
504515

505516
pragma[noinline]
@@ -651,7 +662,8 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
651662

652663
/**
653664
* Holds if this declaration is an implicit function declaration, that is,
654-
* where a function is used before it is declared (under older C standards).
665+
* where a function is used before it is declared (under older C standards,
666+
* or when there were parse errors).
655667
*/
656668
predicate isImplicit() { fun_implicit(underlyingElement(this)) }
657669

cpp/ql/lib/semmle/code/cpp/Type.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Type extends Locatable, @type {
3939

4040
/**
4141
* Gets a specifier of this type, recursively looking through `typedef` and
42-
* `decltype`. For example, in the context of `typedef const int *restrict
43-
* t`, the type `volatile t` has specifiers `volatile` and `restrict` but not
42+
* `decltype`. For example, in the context of `typedef const int *restrict t`,
43+
* the type `volatile t` has specifiers `volatile` and `restrict` but not
4444
* `const` since the `const` is attached to the type being pointed to rather
4545
* than the pointer itself.
4646
*/

cpp/ql/lib/semmle/code/cpp/models/interfaces/FormattingFunction.qll

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,34 @@ abstract class FormattingFunction extends ArrayFunction, TaintFunction {
118118

119119
/**
120120
* Gets the position of the first format argument, corresponding with
121-
* the first format specifier in the format string.
121+
* the first format specifier in the format string. We ignore all
122+
* implicit function definitions.
122123
*/
123124
int getFirstFormatArgumentIndex() {
124-
result = this.getNumberOfParameters() and
125-
// the formatting function either has a definition in the snapshot, or all
125+
// The formatting function either has a definition in the snapshot, or all
126126
// `DeclarationEntry`s agree on the number of parameters (otherwise we don't
127127
// really know the correct number)
128-
(
129-
this.hasDefinition()
130-
or
131-
forall(FunctionDeclarationEntry fde | fde = this.getADeclarationEntry() |
132-
result = fde.getNumberOfParameters()
133-
)
128+
if this.hasDefinition()
129+
then result = this.getDefinition().getNumberOfParameters()
130+
else result = this.getNumberOfExplicitParameters()
131+
}
132+
133+
/**
134+
* Gets a non-implicit function declaration entry.
135+
*/
136+
private FunctionDeclarationEntry getAnExplicitDeclarationEntry() {
137+
result = this.getADeclarationEntry() and
138+
not result.isImplicit()
139+
}
140+
141+
/**
142+
* Gets the number of parameters, excluding any parameters that have been defined
143+
* from implicit function declarations. If there is some inconsistency in the number
144+
* of parameters, then don't return anything.
145+
*/
146+
private int getNumberOfExplicitParameters() {
147+
forex(FunctionDeclarationEntry fde | fde = this.getAnExplicitDeclarationEntry() |
148+
result = fde.getNumberOfParameters()
134149
)
135150
}
136151

cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ private module InvalidPointerToDerefBarrier {
160160
}
161161
}
162162

163+
/**
164+
* BEWARE: This configuration uses an unrestricted sink, so accessing its full
165+
* flow computation or any stages beyond the first 2 will likely diverge.
166+
* Stage 1 will still be fast and we use it to restrict the subsequent sink
167+
* computation.
168+
*/
169+
private module InvalidPointerReachesConfig implements DataFlow::ConfigSig {
170+
predicate isSource(DataFlow::Node source) { invalidPointerToDerefSource(_, _, source) }
171+
172+
predicate isSink(DataFlow::Node sink) { any() }
173+
174+
predicate isBarrier(DataFlow::Node node) { InvalidPointerToDerefConfig::isBarrier(node) }
175+
176+
int fieldFlowBranchLimit() { result = invalidPointerToDereferenceFieldFlowBranchLimit() }
177+
}
178+
179+
private module InvalidPointerReachesFlow = DataFlow::Global<InvalidPointerReachesConfig>;
180+
181+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
182+
163183
/**
164184
* A configuration to track flow from a pointer-arithmetic operation found
165185
* by `AllocToInvalidPointerConfig` to a dereference of the pointer.
@@ -173,8 +193,13 @@ private module InvalidPointerToDerefConfig implements DataFlow::StateConfigSig {
173193
invalidPointerToDerefSource(_, pai, source)
174194
}
175195

176-
pragma[inline]
177-
predicate isSink(DataFlow::Node sink) { isInvalidPointerDerefSink(sink, _, _, _, _) }
196+
predicate isSink(DataFlow::Node sink) {
197+
exists(DataFlowImplCommon::NodeEx n |
198+
InvalidPointerReachesFlow::Stages::Stage1::sinkNode(n, _) and
199+
n.asNode() = sink and
200+
isInvalidPointerDerefSink(sink, _, _, _, _)
201+
)
202+
}
178203

179204
predicate isSink(DataFlow::Node sink, FlowState pai) { none() }
180205

0 commit comments

Comments
 (0)