Skip to content

Commit 6b1ac73

Browse files
authored
Merge pull request github#7177 from ihsinme/ihsinme-patch-6141
fix request for cpp exceptions
2 parents de1269f + 70081de commit 6b1ac73

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-703/FindIncorrectlyUsedExceptions.ql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ where
3838
fc.getTargetType().(Class).getABaseClass+().hasGlobalOrStdName("exception") or
3939
fc.getTargetType().(Class).getABaseClass+().hasGlobalOrStdName("CException")
4040
) and
41+
fc instanceof ExprInVoidContext and
4142
not fc.isInMacroExpansion() and
42-
not exists(ThrowExpr texp | fc.getEnclosingStmt() = texp.getEnclosingStmt()) and
43-
not exists(FunctionCall fctmp | fctmp.getAnArgument() = fc) and
44-
not fc instanceof ConstructorDirectInit and
45-
not fc.getEnclosingStmt() instanceof DeclStmt and
46-
not fc instanceof ConstructorDelegationInit and
47-
not fc.getParent() instanceof Initializer and
48-
not fc.getParent() instanceof AllocationExpr and
49-
msg = "This object does not generate an exception."
43+
msg = "Object creation of exception type on stack. Did you forget the throw keyword?"
5044
select fc, msg
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:35:3:35:33 | call to runtime_error | This object does not generate an exception. |
1+
| test.cpp:35:3:35:33 | call to runtime_error | Object creation of exception type on stack. Did you forget the throw keyword? |
22
| test.cpp:41:3:41:11 | call to funcTest1 | There is an exception in the function that requires your attention. |
33
| test.cpp:42:3:42:9 | call to DllMain | DllMain contains an exeption not wrapped in a try..catch block. |

0 commit comments

Comments
 (0)