Adds SEH exception edge types, disjoint from normal C++ edges. Does not apply the edges yet, just stipulates the types.

This commit is contained in:
REDMOND\brodes
2024-11-20 14:37:32 -05:00
parent 6aa74123af
commit 4078d79f2a
4 changed files with 21 additions and 7 deletions

View File

@@ -3,12 +3,13 @@
*/
private import internal.EdgeKindInternal
private import codeql.util.Boolean
private newtype TEdgeKind =
TGotoEdge() or // Single successor (including fall-through)
TTrueEdge() or // 'true' edge of conditional branch
TFalseEdge() or // 'false' edge of conditional branch
TExceptionEdge() or // Thrown exception
TExceptionEdge(Boolean isSeh) or // Thrown exception, true for SEH exceptions, false otherwise
TDefaultEdge() or // 'default' label of switch
TCaseEdge(string minValue, string maxValue) {
// Case label of switch
@@ -54,7 +55,18 @@ class FalseEdge extends EdgeKind, TFalseEdge {
* instruction's evaluation throws an exception.
*/
class ExceptionEdge extends EdgeKind, TExceptionEdge {
final override string toString() { result = "Exception" }
Boolean isSeh; //true for Structured Exception Handling, false for C++ exceptions
ExceptionEdge() { this = TExceptionEdge(isSeh) }
/**
* Holds if the exception is a Structured Exception Handling (SEH) exception.
*/
final predicate isSeh() { isSeh = true }
final override string toString() {
if isSeh = true then result = "SEH Exception" else result = "C++ Exception"
}
}
/**
@@ -122,8 +134,10 @@ module EdgeKind {
/**
* Gets the single instance of the `ExceptionEdge` class.
* Gets the instance of the `ExceptionEdge` class.
* `isSeh` is true if the exception is an SEH exception, and false for a C++ edge.
*/
ExceptionEdge exceptionEdge() { result = TExceptionEdge() }
ExceptionEdge exceptionEdge(Boolean isSeh) { result = TExceptionEdge(isSeh) }
/**
* Gets the single instance of the `DefaultEdge` class.

View File

@@ -88,7 +88,7 @@ abstract class TranslatedCall extends TranslatedExpr {
result = this.getParent().getChildSuccessor(this, kind)
or
this.mayThrowException() and
kind instanceof ExceptionEdge and
kind = EdgeKind::exceptionEdge(false) and
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
)
}

View File

@@ -3039,7 +3039,7 @@ class TranslatedDestructorsAfterThrow extends TranslatedElement, TTranslatedDest
or
// And otherwise, exit this element with an exceptional edge
not exists(this.getChild(id + 1)) and
kind instanceof ExceptionEdge and
kind = EdgeKind::exceptionEdge(false) and
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
)
}
@@ -3078,7 +3078,7 @@ abstract class TranslatedThrowExpr extends TranslatedNonConstantExpr {
result = this.getDestructors().getFirstInstruction(kind)
or
not exists(this.getDestructors()) and
kind instanceof ExceptionEdge and
kind = EdgeKind::exceptionEdge(false) and
result = this.getParent().getExceptionSuccessorInstruction(any(GotoEdge edge))
)
}

View File

@@ -932,7 +932,7 @@ class TranslatedCatchByTypeHandler extends TranslatedHandler {
kind instanceof GotoEdge and
result = this.getParameter().getFirstInstruction(kind)
or
kind instanceof ExceptionEdge and
kind = EdgeKind::exceptionEdge(false) and
if exists(this.getDestructors())
then result = this.getDestructors().getFirstInstruction(any(GotoEdge edge))
else result = this.getParent().(TranslatedTryStmt).getNextHandler(this, any(GotoEdge edge))