File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < stdint.h>
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+ }
You can’t perform that action at this time.
0 commit comments