Skip to content

Commit 4078d79

Browse files
committed
Adds SEH exception edge types, disjoint from normal C++ edges. Does not apply the edges yet, just stipulates the types.
1 parent 6aa7412 commit 4078d79

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

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

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

55
private import internal.EdgeKindInternal
6+
private import codeql.util.Boolean
67

78
private newtype TEdgeKind =
89
TGotoEdge() or // Single successor (including fall-through)
910
TTrueEdge() or // 'true' edge of conditional branch
1011
TFalseEdge() or // 'false' edge of conditional branch
11-
TExceptionEdge() or // Thrown exception
12+
TExceptionEdge(Boolean isSeh) or // Thrown exception, true for SEH exceptions, false otherwise
1213
TDefaultEdge() or // 'default' label of switch
1314
TCaseEdge(string minValue, string maxValue) {
1415
// Case label of switch
@@ -54,7 +55,18 @@ class FalseEdge extends EdgeKind, TFalseEdge {
5455
* instruction's evaluation throws an exception.
5556
*/
5657
class ExceptionEdge extends EdgeKind, TExceptionEdge {
57-
final override string toString() { result = "Exception" }
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+
}
5870
}
5971

6072
/**
@@ -122,8 +134,10 @@ module EdgeKind {
122134

123135
/**
124136
* 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.
125139
*/
126-
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
140+
ExceptionEdge exceptionEdge(Boolean isSeh) { result = TExceptionEdge(isSeh) }
127141

128142
/**
129143
* Gets the single instance of the `DefaultEdge` class.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ abstract class TranslatedCall extends TranslatedExpr {
8888
result = this.getParent().getChildSuccessor(this, kind)
8989
or
9090
this.mayThrowException() and
91-
kind instanceof ExceptionEdge and
91+
kind = EdgeKind::exceptionEdge(false) and
9292
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
9393
)
9494
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ class TranslatedDestructorsAfterThrow extends TranslatedElement, TTranslatedDest
30393039
or
30403040
// And otherwise, exit this element with an exceptional edge
30413041
not exists(this.getChild(id + 1)) and
3042-
kind instanceof ExceptionEdge and
3042+
kind = EdgeKind::exceptionEdge(false) and
30433043
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
30443044
)
30453045
}
@@ -3078,7 +3078,7 @@ abstract class TranslatedThrowExpr extends TranslatedNonConstantExpr {
30783078
result = this.getDestructors().getFirstInstruction(kind)
30793079
or
30803080
not exists(this.getDestructors()) and
3081-
kind instanceof ExceptionEdge and
3081+
kind = EdgeKind::exceptionEdge(false) and
30823082
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
30833083
)
30843084
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ class TranslatedCatchByTypeHandler extends TranslatedHandler {
932932
kind instanceof GotoEdge and
933933
result = this.getParameter().getFirstInstruction(kind)
934934
or
935-
kind instanceof ExceptionEdge and
935+
kind = EdgeKind::exceptionEdge(false) and
936936
if exists(this.getDestructors())
937937
then result = this.getDestructors().getFirstInstruction(any(GotoEdge edge))
938938
else result = this.getParent().(TranslatedTryStmt).getNextHandler(this, any(GotoEdge edge))

0 commit comments

Comments
 (0)