Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added undefined throwing function. #17397

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,26 @@

final override predicate mayThrowException(boolean unconditional) { unconditional = true }
}

/**
* Calls to functions in a try statement with no body
* are assumed to potentially (not unconditionally) throw anything.
*/
Comment on lines +11 to +14

Check warning

Code scanning / CodeQL

Class QLDoc style. Warning

The QLDoc for a class should start with 'A', 'An', or 'The'.
class UndefinedFunction extends ThrowingFunction {
UndefinedFunction() {
exists(Stmt t, Call c |
t.(TryStmt).getStmt().getAChild*() = c or
t.(MicrosoftTryStmt).getStmt().getAChild*() = c
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
|
this = c.getTarget() and
not this.hasDefinition() and
// Ideally do not mark any function as an UndefinedFunction if it is
// already defined as a throwing function, especially if it is
// already defined as unconditionaly throwing. This leads to
// non-monotonic recursion, so this is a workaround.
not this instanceof WindowsDriverFunction
)
}

final override predicate mayThrowException(boolean unconditional) { unconditional = false }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Modeling functions with no body as potentially throwing.
83 changes: 2 additions & 81 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4207,24 +4207,6 @@ generic.c:
# 3| Type = [IntType] int
# 3| Value = [Literal] 1
# 3| ValueCategory = prvalue
# 3| getLeftOperand().getFullyConverted(): [C11GenericExpr] _Generic
# 3| Type = [IntType] unsigned int
# 3| ValueCategory = prvalue(load)
# 3| getControllingExpr(): [VariableAccess] r
# 3| Type = [IntType] unsigned int
# 3| ValueCategory = prvalue(load)
# 3| getAssociationType(0): [TypeName] unsigned int
# 3| Type = [IntType] unsigned int
# 3| ValueCategory = prvalue
# 3| getAssociationExpr(0): [ReuseExpr] reuse of x
# 3| Type = [IntType] unsigned int
# 3| ValueCategory = lvalue
# 3| getAssociationType(1): [TypeName] int
# 3| Type = [IntType] int
# 3| ValueCategory = prvalue
# 3| getAssociationExpr(1): [VariableAccess] y
# 3| Type = [IntType] int
# 3| ValueCategory = lvalue
# 3| getRightOperand().getFullyConverted(): [CStyleCast] (unsigned int)...
# 3| Conversion = [IntegralConversion] integral conversion
# 3| Type = [IntType] unsigned int
Expand All @@ -4249,29 +4231,6 @@ generic.c:
# 16| getExpr(): [ArrayToPointerConversion] array to pointer conversion
# 16| Type = [CharPointerType] char *
# 16| ValueCategory = prvalue
# 16| getExpr(): [C11GenericExpr] _Generic
# 16| Type = [ArrayType] char[4]
# 16| Value = [C11GenericExpr] int
# 16| ValueCategory = lvalue
# 16| getControllingExpr(): [VariableAccess] i
# 16| Type = [IntType] int
# 16| ValueCategory = prvalue(load)
# 16| getAssociationType(0): [TypeName] int
# 16| Type = [IntType] int
# 16| ValueCategory = prvalue
# 16| getAssociationExpr(0): [ReuseExpr] reuse of int
# 16| Type = [ArrayType] char[4]
# 16| ValueCategory = lvalue
# 16| getAssociationType(1): [TypeName] void
# 16| Type = [VoidType] void
# 16| ValueCategory = prvalue
# 16| getAssociationExpr(1): unknown
# 16| Type = [ArrayType] char[8]
# 16| Value = [StringLiteral] "unknown"
# 16| ValueCategory = lvalue
# 16| getControllingExpr().getFullyConverted(): [ParenthesisExpr] (...)
# 16| Type = [IntType] int
# 16| ValueCategory = prvalue(load)
# 19| [TopLevelFunction] char const* c11_generic_test_with_constant_and_no_macro()
# 19| <params>:
# 20| getEntryPoint(): [BlockStmt] { ... }
Expand All @@ -4290,26 +4249,6 @@ generic.c:
# 23| getExpr(): [ArrayToPointerConversion] array to pointer conversion
# 23| Type = [CharPointerType] char *
# 23| ValueCategory = prvalue
# 23| getExpr(): [C11GenericExpr] _Generic
# 23| Type = [ArrayType] char[4]
# 23| Value = [C11GenericExpr] int
# 23| ValueCategory = lvalue
# 23| getControllingExpr(): [VariableAccess] i
# 23| Type = [IntType] int
# 23| ValueCategory = prvalue(load)
# 23| getAssociationType(0): [TypeName] int
# 23| Type = [IntType] int
# 23| ValueCategory = prvalue
# 23| getAssociationExpr(0): [ReuseExpr] reuse of int
# 23| Type = [ArrayType] char[4]
# 23| ValueCategory = lvalue
# 23| getAssociationType(1): [TypeName] void
# 23| Type = [VoidType] void
# 23| ValueCategory = prvalue
# 23| getAssociationExpr(1): unknown
# 23| Type = [ArrayType] char[8]
# 23| Value = [StringLiteral] "unknown"
# 23| ValueCategory = lvalue
# 26| [TopLevelFunction] void c11_generic_test_test_with_cast(int)
# 26| <params>:
# 26| getParameter(0): [Parameter] y
Expand All @@ -4328,28 +4267,10 @@ generic.c:
# 28| getRValue(): [VariableAccess] y
# 28| Type = [IntType] int
# 28| ValueCategory = prvalue(load)
# 28| getRValue().getFullyConverted(): [C11GenericExpr] _Generic
# 28| getRValue().getFullyConverted(): [CStyleCast] (unsigned int)...
# 28| Conversion = [IntegralConversion] integral conversion
# 28| Type = [IntType] unsigned int
# 28| ValueCategory = prvalue
# 28| getControllingExpr(): [VariableAccess] r
# 28| Type = [IntType] unsigned int
# 28| ValueCategory = prvalue(load)
# 28| getAssociationType(0): [TypeName] unsigned int
# 28| Type = [IntType] unsigned int
# 28| ValueCategory = prvalue
# 28| getAssociationExpr(0): [ReuseExpr] reuse of y
# 28| Type = [IntType] int
# 28| ValueCategory = prvalue
# 28| getAssociationType(1): [TypeName] int
# 28| Type = [IntType] int
# 28| ValueCategory = prvalue
# 28| getAssociationExpr(1): [VariableAccess] y
# 28| Type = [IntType] int
# 28| ValueCategory = lvalue
# 28| getExpr(): [CStyleCast] (unsigned int)...
# 28| Conversion = [IntegralConversion] integral conversion
# 28| Type = [IntType] unsigned int
# 28| ValueCategory = prvalue
# 29| getStmt(2): [ReturnStmt] return ...
ir.c:
# 5| [TopLevelFunction] int getX(MyCoords*)
Expand Down
Loading
Loading