Skip to content

Commit 88372df

Browse files
authored
Merge pull request github#6495 from andersfugmann/more_buffer_overrun_tests
More buffer overrun tests
2 parents 50a4345 + 666d591 commit 88372df

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
typedef unsigned char uint8_t;
2+
#define SIZE (32)
3+
4+
void test_buffer_overrun_in_for_loop()
5+
{
6+
uint8_t data[SIZE] = {0};
7+
for (int x = 0; x < SIZE * 2; x++) {
8+
data[x] = 0x41; // BAD [NOT DETECTED]
9+
}
10+
}
11+
12+
void test_buffer_overrun_in_while_loop_using_pointer_arithmetic()
13+
{
14+
uint8_t data[SIZE] = {0};
15+
int offset = 0;
16+
while (offset < SIZE * 2) {
17+
*(data + offset) = 0x41; // BAD [NOT DETECTED]
18+
offset++;
19+
}
20+
}
21+
22+
void test_buffer_overrun_in_while_loop_using_array_indexing()
23+
{
24+
uint8_t data[SIZE] = {0};
25+
int offset = 0;
26+
while (offset < SIZE * 2) {
27+
data[offset] = 0x41; // BAD [NOT DETECTED]
28+
offset++;
29+
}
30+
}
31+
32+
int main(int argc, char *argv[])
33+
{
34+
test_buffer_overrun_in_for_loop();
35+
test_buffer_overrun_in_while_loop_using_pointer_arithmetic();
36+
test_buffer_overrun_in_while_loop_using_array_indexing();
37+
38+
return 0;
39+
}

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void test6(bool cond)
114114

115115
c = 100;
116116
buffer[c] = 'x'; // BAD: over-write [NOT DETECTED]
117-
ch = buffer[c]; // BAD: under-read [NOT DETECTED]
117+
ch = buffer[c]; // BAD: over-read [NOT DETECTED]
118118

119119
d = 0;
120120
d = 1000;

0 commit comments

Comments
 (0)