-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CPP: Add a query to find incorrectly used exceptions. #6082
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
Conversation
cpp/ql/src/experimental/Security/CWE/CWE-703/FindIncorrectlyUsedExceptions.ql
Show resolved
Hide resolved
| not fc instanceof ConstructorDirectInit and | ||
| not fc.getEnclosingStmt() instanceof DeclStmt and | ||
| not fc instanceof ConstructorDelegationInit and | ||
| msg = "This object does not generate an exception." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case looks interesting. Can you give an example (preferably a test case) demonstrating what it is trying to catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I am looking for objects of type std :: exception that do not throw exceptions.
a basic example can be seen in PR. I will try to make a test case a little later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, broadly, it's looking for cases where a std::exception object is created but not as part of a throw? e.g. the author writes
std::bad_alloc();
when they meant to write:
throw std::bad_alloc();
|
Good day. |
| <li> | ||
| CERT CPP Coding Standard: | ||
| <a href="https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL57-CPP.+Do+not+let+exceptions+escape+from+destructors+or+deallocation+functions">DCL57-CPP. Do not let exceptions escape from destructors or deallocation functions</a>. | ||
| <a href="https://wiki.sei.cmu.edu/confluence/display/java/ERR00-J.+Do+not+suppress+or+ignore+checked+exceptions">ERR00-J. Do not suppress or ignore checked exceptions</a>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This page is about the Java language. Please would you replace it with an equivalent C/C++ link?
| not ts.getACatchClause().isEmpty() | ||
| ) and | ||
| msg = "This distructor contains exeption no wrapped to try..catch blocks" | ||
| msg = "Exception inside this function requires more handling." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is now looking for a throw statement inside a called function, that is not caught/handled inside that function. This seems like something that normal correct code would be doing fairly frequently, for example a function that's supposed to access a file might reasonably throw an exception if that file doesn't exist.
|
it looks stupid. ( sorry for wasting time. |
Good day.
in this request I am looking for errors when using exceptions.
I have identified 2 main areas:
Regarding fixes in real software, my proposal is pending, but I plan to continue searching.
assimp/assimp#3954