Skip to content

Commit 4c17999

Browse files
committed
MEM53-CPP: Remove FP introduced by upgrade to 2.15.5
Flow through realloc was added in the standard library, so move to barrier instead of node filter
1 parent 8cb2a4c commit 4c17999

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

cpp/cert/src/rules/MEM53-CPP/ManuallyManagedLifetime.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ module AllocToStaticCastConfig implements DataFlow::ConfigSig {
1414
predicate isSource(DataFlow::Node source) {
1515
exists(AllocationExpr ae |
1616
ae.getType().getUnspecifiedType() instanceof VoidPointerType and
17-
source.asExpr() = ae and
18-
// Ignore realloc, as that memory may already be partially constructed
19-
not ae.(FunctionCall).getTarget().getName().toLowerCase().matches("%realloc%")
17+
source.asExpr() = ae
2018
)
2119
}
2220

21+
predicate isBarrier(DataFlow::Node sanitizer) {
22+
// Ignore realloc, as that memory may already be partially constructed
23+
sanitizer.asExpr().(FunctionCall).getTarget().getName().toLowerCase().matches("%realloc%")
24+
}
25+
2326
predicate isSink(DataFlow::Node sink) {
2427
exists(StaticOrCStyleCast sc, Class nonTrivialClass |
2528
sc.getExpr() = sink.asExpr() and

cpp/cert/test/rules/MEM53-CPP/MissingConstructorCallForManuallyManagedObject.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
edges
2-
| test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc |
32
nodes
43
| test.cpp:16:26:16:31 | call to malloc | semmle.label | call to malloc |
54
| test.cpp:17:38:17:43 | call to malloc | semmle.label | call to malloc |
@@ -10,8 +9,6 @@ nodes
109
| test.cpp:47:26:47:39 | call to operator new | semmle.label | call to operator new |
1110
| test.cpp:49:29:49:42 | call to operator new | semmle.label | call to operator new |
1211
| test.cpp:51:29:51:42 | call to operator new | semmle.label | call to operator new |
13-
| test.cpp:65:21:65:34 | call to operator new | semmle.label | call to operator new |
14-
| test.cpp:67:26:67:32 | call to realloc | semmle.label | call to realloc |
1512
subpaths
1613
#select
1714
| test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | test.cpp:16:26:16:31 | call to malloc | Allocation to cast without constructor call |
@@ -23,4 +20,3 @@ subpaths
2320
| test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | test.cpp:47:26:47:39 | call to operator new | Allocation to cast without constructor call |
2421
| test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | test.cpp:49:29:49:42 | call to operator new | Allocation to cast without constructor call |
2522
| test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | test.cpp:51:29:51:42 | call to operator new | Allocation to cast without constructor call |
26-
| test.cpp:67:26:67:32 | call to realloc | test.cpp:65:21:65:34 | call to operator new | test.cpp:67:26:67:32 | call to realloc | Allocation to cast without constructor call |

cpp/cert/test/rules/MEM53-CPP/test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void test_no_constructor_but_has_destructor() {
6363

6464
void test_realloc() {
6565
void *goodAlloc = ::operator new(sizeof(ClassA));
66-
ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT
67-
ClassA *a2 = (ClassA *)realloc(
68-
goodAlloc, sizeof(ClassA) * 2); // COMPLIANT [FALSE_POSITIVE]
66+
ClassA *a1 = new (goodAlloc) ClassA{1}; // COMPLIANT
67+
ClassA *a2 = (ClassA *)realloc(goodAlloc, sizeof(ClassA) * 2); // COMPLIANT
6968
}

0 commit comments

Comments
 (0)