Skip to content

Commit 6a7b2e4

Browse files
committed
C++: Add failing test.
1 parent 0e3369f commit 6a7b2e4

File tree

1 file changed

+11
-0
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-193

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,15 @@ void test16_with_malloc(size_t index) {
848848
int* newname = (int*)malloc(size);
849849
newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE]
850850
}
851+
}
852+
853+
# define MyMalloc(size) malloc(((size) == 0 ? 1 : (size)))
854+
855+
void test_regression(size_t size) {
856+
int* p = (int*)MyMalloc(size + 1);
857+
int* chend = p + (size + 1);
858+
859+
if(p <= chend) {
860+
*p = 42; // BAD [NOT DETECTED]
861+
}
851862
}

0 commit comments

Comments
 (0)