Skip to content

Commit defa869

Browse files
committed
Merge remote-tracking branch 'mathiasvp/final-alias-edge-kind' into brodes/seh_flow_phase2_splitting_seh_edges
# Conflicts: # cpp/ql/lib/semmle/code/cpp/ir/implementation/EdgeKind.qll
2 parents 779376e + 667abb1 commit defa869

File tree

263 files changed

+2433
-2703
lines changed

Some content is hidden

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

263 files changed

+2433
-2703
lines changed

cpp/ql/lib/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 3.0.0
2+
3+
### Breaking Changes
4+
5+
* Deleted the old deprecated data flow API that was based on extending a configuration class. See https://github.blog/changelog/2023-08-14-new-dataflow-api-for-writing-custom-codeql-queries for instructions on migrating your queries to use the new API.
6+
7+
### Deprecated APIs
8+
9+
* The `NonThrowing` class (`semmle.code.cpp.models.interfaces.NonThrowing`) has been deprecated. Please use the `NonCppThrowingFunction` class instead.
10+
111
## 2.1.1
212

313
No user-facing changes.

cpp/ql/lib/change-notes/2024-11-18-throwing-functions.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
---
2-
category: breaking
3-
---
1+
## 3.0.0
2+
3+
### Breaking Changes
4+
45
* Deleted the old deprecated data flow API that was based on extending a configuration class. See https://github.blog/changelog/2023-08-14-new-dataflow-api-for-writing-custom-codeql-queries for instructions on migrating your queries to use the new API.
6+
7+
### Deprecated APIs
8+
9+
* The `NonThrowing` class (`semmle.code.cpp.models.interfaces.NonThrowing`) has been deprecated. Please use the `NonCppThrowingFunction` class instead.

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.1.1
2+
lastReleaseVersion: 3.0.0

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.1.2-dev
2+
version: 3.0.1-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

cpp/ql/lib/semmle/code/cpp/ir/implementation/EdgeKind.qll

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
*/
44

55
private import internal.EdgeKindInternal
6-
private import codeql.util.Boolean
76

87
private newtype TEdgeKind =
98
TGotoEdge() or // Single successor (including fall-through)
109
TTrueEdge() or // 'true' edge of conditional branch
1110
TFalseEdge() or // 'false' edge of conditional branch
12-
TExceptionEdge(Boolean isSeh) or // Thrown exception, true for SEH exceptions, false otherwise
11+
TExceptionEdge() or // Thrown exception
1312
TDefaultEdge() or // 'default' label of switch
1413
TCaseEdge(string minValue, string maxValue) {
1514
// Case label of switch
@@ -21,67 +20,58 @@ private newtype TEdgeKind =
2120
* `Instruction` or `IRBlock` has at most one successor of any single
2221
* `EdgeKind`.
2322
*/
24-
abstract class EdgeKind extends TEdgeKind {
23+
abstract private class EdgeKindImpl extends TEdgeKind {
2524
/** Gets a textual representation of this edge kind. */
2625
abstract string toString();
2726
}
2827

28+
final class EdgeKind = EdgeKindImpl;
29+
2930
/**
3031
* A "goto" edge, representing the unconditional successor of an `Instruction`
3132
* or `IRBlock`.
3233
*/
33-
class GotoEdge extends EdgeKind, TGotoEdge {
34+
class GotoEdge extends EdgeKindImpl, TGotoEdge {
3435
final override string toString() { result = "Goto" }
3536
}
3637

3738
/**
3839
* A "true" edge, representing the successor of a conditional branch when the
3940
* condition is non-zero.
4041
*/
41-
class TrueEdge extends EdgeKind, TTrueEdge {
42+
class TrueEdge extends EdgeKindImpl, TTrueEdge {
4243
final override string toString() { result = "True" }
4344
}
4445

4546
/**
4647
* A "false" edge, representing the successor of a conditional branch when the
4748
* condition is zero.
4849
*/
49-
class FalseEdge extends EdgeKind, TFalseEdge {
50+
class FalseEdge extends EdgeKindImpl, TFalseEdge {
5051
final override string toString() { result = "False" }
5152
}
5253

5354
/**
5455
* An "exception" edge, representing the successor of an instruction when that
5556
* instruction's evaluation throws an exception.
5657
*/
57-
class ExceptionEdge extends EdgeKind, TExceptionEdge {
58-
Boolean isSeh; //true for Structured Exception Handling, false for C++ exceptions
59-
60-
ExceptionEdge() { this = TExceptionEdge(isSeh) }
61-
62-
/**
63-
* Holds if the exception is a Structured Exception Handling (SEH) exception.
64-
*/
65-
final predicate isSeh() { isSeh = true }
66-
67-
final override string toString() {
68-
if isSeh = true then result = "SEH Exception" else result = "C++ Exception"
69-
}
58+
class ExceptionEdge extends EdgeKindImpl, TExceptionEdge {
59+
final override string toString() { result = "Exception" }
7060
}
7161

7262
/**
7363
* A "default" edge, representing the successor of a `Switch` instruction when
7464
* none of the case values matches the condition value.
7565
*/
76-
class DefaultEdge extends EdgeKind, TDefaultEdge {
66+
class DefaultEdge extends EdgeKindImpl, TDefaultEdge {
7767
final override string toString() { result = "Default" }
7868
}
7969

8070
/**
8171
* A "case" edge, representing the successor of a `Switch` instruction when the
8272
* the condition value matches a corresponding `case` label.
8373
*/
84-
class CaseEdge extends EdgeKind, TCaseEdge {
74+
class CaseEdge extends EdgeKindImpl, TCaseEdge {
8575
string minValue;
8676
string maxValue;
8777

@@ -134,10 +124,8 @@ module EdgeKind {
134124

135125
/**
136126
* Gets the single instance of the `ExceptionEdge` class.
137-
* Gets the instance of the `ExceptionEdge` class.
138-
* `isSeh` is true if the exception is an SEH exception, and false for a C++ edge.
139127
*/
140-
ExceptionEdge exceptionEdge(Boolean isSeh) { result = TExceptionEdge(isSeh) }
128+
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
141129

142130
/**
143131
* Gets the single instance of the `DefaultEdge` class.

cpp/ql/src/Best Practices/GuardedFree.ql

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ predicate blockContainsPreprocessorBranches(BasicBlock bb) {
2727
)
2828
}
2929

30-
from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
31-
where
30+
/**
31+
* Holds if `gc` ensures that `v` is non-zero when reaching `bb`, and `bb`
32+
* contains a single statement which is `fc`.
33+
*/
34+
pragma[nomagic]
35+
private predicate interesting(GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb) {
3236
gc.ensuresEq(v.getAnAccess(), 0, bb, false) and
3337
fc.getArgument(0) = v.getAnAccess() and
3438
bb = fc.getBasicBlock() and
@@ -39,9 +43,21 @@ where
3943
// Block statement with a single nested statement: if (x) { free(x); }
4044
strictcount(bb.(BlockStmt).getAStmt()) = 1
4145
) and
42-
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1 and
4346
not fc.isInMacroExpansion() and
4447
not blockContainsPreprocessorBranches(bb) and
4548
not (gc instanceof BinaryOperation and not gc instanceof ComparisonOperation) and
4649
not exists(CommaExpr c | c.getAChild*() = fc)
50+
}
51+
52+
/** Holds if `gc` only guards a single block. */
53+
bindingset[gc]
54+
pragma[inline_late]
55+
private predicate guardConditionGuardsUniqueBlock(GuardCondition gc) {
56+
strictcount(BasicBlock bb | gc.ensuresEq(_, 0, bb, _)) = 1
57+
}
58+
59+
from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
60+
where
61+
interesting(gc, fc, v, bb) and
62+
guardConditionGuardsUniqueBlock(gc)
4763
select gc, "unnecessary NULL check before call to $@", fc, "free"

cpp/ql/src/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.3.0
2+
3+
### New Queries
4+
5+
* Added a new high-precision quality query, `cpp/guarded-free`, which detects useless NULL pointer checks before calls to `free`. A variation of this query was originally contributed as an [experimental query by @mario-campos](https://github.com/github/codeql/pull/16331).
6+
7+
### Minor Analysis Improvements
8+
9+
* The "Call to function with fewer arguments than declared parameters" query (`cpp/too-few-arguments`) query no longer produces results if the function has been implicitly declared.
10+
111
## 1.2.7
212

313
No user-facing changes.

cpp/ql/src/change-notes/2024-11-22-too-few-arguments.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
---
2-
category: newQuery
3-
---
1+
## 1.3.0
2+
3+
### New Queries
4+
45
* Added a new high-precision quality query, `cpp/guarded-free`, which detects useless NULL pointer checks before calls to `free`. A variation of this query was originally contributed as an [experimental query by @mario-campos](https://github.com/github/codeql/pull/16331).
6+
7+
### Minor Analysis Improvements
8+
9+
* The "Call to function with fewer arguments than declared parameters" query (`cpp/too-few-arguments`) query no longer produces results if the function has been implicitly declared.

0 commit comments

Comments
 (0)