mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
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:
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user