Skip to content

Commit 42f4625

Browse files
committed
Merge branch 'main' into redsun82/swift-file-label-caching
2 parents 10b7b1f + edc8f6f commit 42f4625

File tree

247 files changed

+3276
-1763
lines changed

Some content is hidden

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

247 files changed

+3276
-1763
lines changed

cpp/ql/lib/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.3.1
2+
3+
### Minor Analysis Improvements
4+
5+
* `AnalysedExpr::isNullCheck` and `AnalysedExpr::isValidCheck` have been updated to handle variable accesses on the left-hand side of the C++ logical "and", and variable declarations in conditions.
6+
17
## 0.3.0
28

39
### Deprecated APIs
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Under certain circumstances a variable declaration that is not also a definition could be associated with a `Variable` that did not have the definition as a `VariableDeclarationEntry`. This is now fixed, and a unique `Variable` will exist that has both the declaration and the definition as a `VariableDeclarationEntry`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
---
2-
category: minorAnalysis
3-
---
4-
* `AnalysedExpr::isNullCheck` and `AnalysedExpr::isValidCheck` have been updated to handle variable accesses on the left-hand side of the the C++ logical and variable declarations in conditions.
1+
## 0.3.1
2+
3+
### Minor Analysis Improvements
4+
5+
* `AnalysedExpr::isNullCheck` and `AnalysedExpr::isValidCheck` have been updated to handle variable accesses on the left-hand side of the C++ logical "and", and variable declarations in conditions.

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: 0.3.0
2+
lastReleaseVersion: 0.3.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: 0.3.1-dev
2+
version: 0.3.2-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import semmle.code.cpp.Location
77
private import semmle.code.cpp.Enclosing
88
private import semmle.code.cpp.internal.ResolveClass
9+
private import semmle.code.cpp.internal.ResolveGlobalVariable
910

1011
/**
1112
* Get the `Element` that represents this `@element`.
@@ -28,9 +29,12 @@ Element mkElement(@element e) { unresolveElement(result) = e }
2829
pragma[inline]
2930
@element unresolveElement(Element e) {
3031
not result instanceof @usertype and
32+
not result instanceof @variable and
3133
result = e
3234
or
3335
e = resolveClass(result)
36+
or
37+
e = resolveGlobalVariable(result)
3438
}
3539

3640
/**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import semmle.code.cpp.Element
66
import semmle.code.cpp.exprs.Access
77
import semmle.code.cpp.Initializer
88
private import semmle.code.cpp.internal.ResolveClass
9+
private import semmle.code.cpp.internal.ResolveGlobalVariable
910

1011
/**
1112
* A C/C++ variable. For example, in the following code there are four
@@ -32,6 +33,8 @@ private import semmle.code.cpp.internal.ResolveClass
3233
* can have multiple declarations.
3334
*/
3435
class Variable extends Declaration, @variable {
36+
Variable() { isVariable(underlyingElement(this)) }
37+
3538
override string getAPrimaryQlClass() { result = "Variable" }
3639

3740
/** Gets the initializer of this variable, if any. */
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
private predicate hasDefinition(@globalvariable g) {
2+
exists(@var_decl vd | var_decls(vd, g, _, _, _) | var_def(vd))
3+
}
4+
5+
private predicate onlyOneCompleteGlobalVariableExistsWithMangledName(@mangledname name) {
6+
strictcount(@globalvariable g | hasDefinition(g) and mangled_name(g, name)) = 1
7+
}
8+
9+
/** Holds if `g` is a unique global variable with a definition named `name`. */
10+
private predicate isGlobalWithMangledNameAndWithDefinition(@mangledname name, @globalvariable g) {
11+
hasDefinition(g) and
12+
mangled_name(g, name) and
13+
onlyOneCompleteGlobalVariableExistsWithMangledName(name)
14+
}
15+
16+
/** Holds if `g` is a global variable without a definition named `name`. */
17+
private predicate isGlobalWithMangledNameAndWithoutDefinition(@mangledname name, @globalvariable g) {
18+
not hasDefinition(g) and
19+
mangled_name(g, name)
20+
}
21+
22+
/**
23+
* Holds if `incomplete` is a global variable without a definition, and there exists
24+
* a unique global variable `complete` with the same name that does have a definition.
25+
*/
26+
private predicate hasTwinWithDefinition(@globalvariable incomplete, @globalvariable complete) {
27+
exists(@mangledname name |
28+
not variable_instantiation(incomplete, complete) and
29+
isGlobalWithMangledNameAndWithoutDefinition(name, incomplete) and
30+
isGlobalWithMangledNameAndWithDefinition(name, complete)
31+
)
32+
}
33+
34+
import Cached
35+
36+
cached
37+
private module Cached {
38+
/**
39+
* If `v` is a global variable without a definition, and there exists a unique
40+
* global variable with the same name that does have a definition, then the
41+
* result is that unique global variable. Otherwise, the result is `v`.
42+
*/
43+
cached
44+
@variable resolveGlobalVariable(@variable v) {
45+
hasTwinWithDefinition(v, result)
46+
or
47+
not hasTwinWithDefinition(v, _) and
48+
result = v
49+
}
50+
51+
cached
52+
predicate isVariable(@variable v) {
53+
not v instanceof @globalvariable
54+
or
55+
v = resolveGlobalVariable(_)
56+
}
57+
}

cpp/ql/src/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.3.0
2+
3+
### Breaking Changes
4+
5+
* Contextual queries and the query libraries they depend on have been moved to the `codeql/cpp-all` package.
6+
17
## 0.2.0
28

39
## 0.1.4

cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
7474

7575
from
7676
MustFlowPathNode source, MustFlowPathNode sink, VariableAddressInstruction var,
77-
ReturnStackAllocatedMemoryConfig conf, Function f
77+
ReturnStackAllocatedMemoryConfig conf
7878
where
79-
conf.hasFlowPath(source, sink) and
79+
conf.hasFlowPath(pragma[only_bind_into](source), pragma[only_bind_into](sink)) and
8080
source.getNode().asInstruction() = var and
8181
// Only raise an alert if we're returning from the _same_ callable as the on that
8282
// declared the stack variable.
83-
var.getEnclosingFunction() = pragma[only_bind_into](f) and
84-
sink.getNode().getEnclosingCallable() = pragma[only_bind_into](f)
83+
var.getEnclosingFunction() = sink.getNode().getEnclosingCallable()
8584
select sink.getNode(), source, sink, "May return stack-allocated memory from $@.", var.getAst(),
8685
var.getAst().toString()

0 commit comments

Comments
 (0)