Skip to content

Commit 432c0b5

Browse files
committed
C++: Add another FP.
1 parent 5a8bed0 commit 432c0b5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/InvalidPointerDeref.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ edges
581581
| test.cpp:238:20:238:32 | new[] | test.cpp:239:5:239:11 | newname |
582582
| test.cpp:239:5:239:11 | newname | test.cpp:239:5:239:18 | access to array |
583583
| test.cpp:239:5:239:18 | access to array | test.cpp:239:5:239:22 | Store: ... = ... |
584+
| test.cpp:248:24:248:30 | call to realloc | test.cpp:249:9:249:9 | p |
585+
| test.cpp:248:24:248:30 | call to realloc | test.cpp:250:22:250:22 | p |
586+
| test.cpp:248:24:248:30 | call to realloc | test.cpp:253:9:253:9 | p |
587+
| test.cpp:253:9:253:9 | p | test.cpp:253:9:253:12 | access to array |
588+
| test.cpp:253:9:253:12 | access to array | test.cpp:253:9:253:16 | Store: ... = ... |
584589
#select
585590
| test.cpp:6:14:6:15 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
586591
| test.cpp:8:14:8:21 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:8:14:8:21 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -601,3 +606,4 @@ edges
601606
| test.cpp:213:5:213:13 | Store: ... = ... | test.cpp:205:23:205:28 | call to malloc | test.cpp:213:5:213:13 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:205:23:205:28 | call to malloc | call to malloc | test.cpp:206:21:206:23 | len | len |
602607
| test.cpp:232:3:232:20 | Store: ... = ... | test.cpp:231:18:231:30 | new[] | test.cpp:232:3:232:20 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:231:18:231:30 | new[] | new[] | test.cpp:232:11:232:15 | index | index |
603608
| test.cpp:239:5:239:22 | Store: ... = ... | test.cpp:238:20:238:32 | new[] | test.cpp:239:5:239:22 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:238:20:238:32 | new[] | new[] | test.cpp:239:13:239:17 | index | index |
609+
| test.cpp:253:9:253:16 | Store: ... = ... | test.cpp:248:24:248:30 | call to realloc | test.cpp:253:9:253:16 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:248:24:248:30 | call to realloc | call to realloc | test.cpp:253:11:253:11 | i | i |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/test.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,18 @@ void test16(unsigned index) {
238238
int* newname = new int[size];
239239
newname[index] = 0; // GOOD [FALSE POSITIVE]
240240
}
241-
}
241+
}
242+
243+
void *realloc(void *, unsigned);
244+
245+
void test17(unsigned *p, unsigned x, unsigned k) {
246+
if(k > 0 && p[1] <= p[0]){
247+
unsigned n = 3*p[0] + k;
248+
p = (unsigned*)realloc(p, n);
249+
p[0] = n;
250+
unsigned i = p[1];
251+
// The following access is okay because:
252+
// n = 2*p[0] + k >= p[0] + k >= p[1] + k > p[1] = i
253+
p[i] = x; // GOOD [FALSE POSITIVE]
254+
}
255+
}

0 commit comments

Comments
 (0)