Skip to content

Commit 3f72a1a

Browse files
authored
Merge pull request github#6471 from MathiasVP/fix-fp-in-incorrect-allocation-error-handling
C++: Fix false-positive in 'cpp/incorrect-allocation-error-handling'
2 parents c8ded7e + 8d594db commit 3f72a1a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class ThrowingAllocator extends Function {
182182
// 3. the allocator isn't marked with `throw()` or `noexcept`.
183183
not exists(this.getBlock()) and
184184
not exists(Parameter p | p = this.getAParameter() |
185-
p.getUnspecifiedType() instanceof NoThrowType
185+
p.getUnspecifiedType().stripType() instanceof NoThrowType
186186
) and
187187
not this.isNoExcept() and
188188
not this.isNoThrow()

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
234+
if(p == nullptr) {}
235+
}

0 commit comments

Comments
 (0)