Skip to content

Commit c12837c

Browse files
committed
C++: Fix false negative.
1 parent 7b8a51f commit c12837c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-570/IncorrectAllocationErrorHandling.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ class BadAllocType extends Class {
168168
}
169169

170170
/**
171-
* A catch block that catches a `std::bad_alloc` (or any of its subclasses), or a catch
171+
* A catch block that catches a `std::bad_alloc` (or any of its superclasses), or a catch
172172
* block that catches every exception (i.e., `catch(...)`).
173173
*/
174174
class BadAllocCatchBlock extends CatchBlock {
175175
BadAllocCatchBlock() {
176176
this.getParameter().getUnspecifiedType().stripType() =
177-
any(BadAllocType badAlloc).getADerivedClass*()
177+
any(BadAllocType badAlloc).getABaseClass*()
178178
or
179179
not exists(this.getParameter())
180180
}

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/IncorrectAllocationErrorHandling.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
| test.cpp:96:10:96:36 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
1616
| test.cpp:151:9:151:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:152:15:152:18 | { ... } | This catch block |
1717
| test.cpp:199:15:199:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:201:16:201:19 | { ... } | This catch block |
18+
| test.cpp:212:14:212:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:213:34:213:36 | { ... } | This catch block |

0 commit comments

Comments
 (0)