Skip to content

Commit c2b1da0

Browse files
committed
C++: Add FP testcase with an 'new' that has a 'std::nothrow&' parameter, but not a 'noexcept' specifier. This case was previously not reported because of the 'noexcept' specifier, and apparently the 'std::nothrow' case was broken all along.
1 parent 15db6df commit c2b1da0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
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 |
1818
| test.cpp:212:14:212:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:213:34:213:36 | { ... } | This catch block |
19+
| test.cpp:233:12:233:36 | new | This allocation cannot return null. $@ is unnecessary. | test.cpp:234:6:234:17 | ... == ... | This check |

cpp/ql/test/query-tests/Security/CWE/CWE-570/test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,12 @@ void good_new_catch_exception_in_conversion() {
224224
try {
225225
long* p = (long*) new int; // GOOD
226226
} catch(const std::bad_alloc&) { }
227-
}
227+
}
228+
229+
// The 'n' parameter is just to distinquish it from the overload further up in this file.
230+
void *operator new(std::size_t, int n, const std::nothrow_t &);
231+
232+
void test_operator_new_without_exception_spec() {
233+
int* p = new(42, std::nothrow) int; // GOOD [FALSE POSITIVE]
234+
if(p == nullptr) {}
235+
}

0 commit comments

Comments
 (0)