File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ void test6(bool cond)
114
114
115
115
c = 100 ;
116
116
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]
118
118
119
119
d = 0 ;
120
120
d = 1000 ;
You can’t perform that action at this time.
0 commit comments