Skip to content

Commit 439fe41

Browse files
committed
C++: Add a couple more test cases.
1 parent d2dd19a commit 439fe41

File tree

1 file changed

+25
-0
lines changed
  • cpp/ql/test/experimental/query-tests/Security/CWE/CWE-401/semmle/tests

1 file changed

+25
-0
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-401/semmle/tests/test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,28 @@ unsigned char *noBadResize_4_1(unsigned char *buffer, size_t currentSize, size_t
319319

320320
return buffer;
321321
}
322+
323+
unsigned char * badResize_5_2(unsigned char *buffer, size_t currentSize, size_t newSize, int cond)
324+
{
325+
// BAD: on unsuccessful call to realloc, we will lose a pointer to a valid memory block [NOT DETECTED]
326+
if (currentSize < newSize)
327+
{
328+
buffer = (unsigned char *)realloc(buffer, newSize);
329+
}
330+
if (cond)
331+
{
332+
abort(); // irrelevant
333+
}
334+
return buffer;
335+
}
336+
337+
unsigned char * badResize_5_1(unsigned char *buffer, size_t currentSize, size_t newSize, int cond)
338+
{
339+
// BAD: on unsuccessful call to realloc, we will lose a pointer to a valid memory block [NOT DETECTED]
340+
if (currentSize < newSize)
341+
{
342+
buffer = (unsigned char *)realloc(buffer, newSize);
343+
assert(cond); // irrelevant
344+
}
345+
return buffer;
346+
}

0 commit comments

Comments
 (0)