Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/taint-index-pr106229.c

raw
1 #include <stdint.h>
2
3 /* Attacker-controlled 8 bit values where the array isn't
4 necessarily big enough. We should warn about these. */
5
6 struct st_s8_field_255_elements
7 {
8 int8_t idx;
9 char buf[255];
10 };
11
12 char __attribute__((tainted_args))
13 test_s8_field_255_elements (struct st_s8_field_255_elements s)
14 {
15 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
16 }
17
18 struct st_u8_field_255_elements
19 {
20 uint8_t idx;
21 char buf[255];
22 };
23
24 char __attribute__((tainted_args))
25 test_u8_field_255_elements (struct st_u8_field_255_elements s)
26 {
27 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
28 }
29
30 /* Attacker-controlled 8 bit values where the array is
31 big enough, but where the value might be signed. */
32
33 struct st_s8_field_256_elements
34 {
35 int8_t idx;
36 char buf[256];
37 };
38
39 char __attribute__((tainted_args))
40 test_s8_field_256_elements (struct st_s8_field_256_elements s)
41 {
42 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
43 }
44
45 struct st_u8_field_256_elements
46 {
47 uint8_t idx;
48 char buf[256];
49 };
50
51 char __attribute__((tainted_args))
52 test_u8_field_256_elements (struct st_u8_field_256_elements s)
53 {
54 return s.buf[s.idx]; /* { dg-bogus "tainted-array-index" } */
55 }
56
57 /* Attacker-controlled 16 bit values where the array isn't
58 necessarily big enough. We should warn about these. */
59
60 struct st_s16_field_256_elements
61 {
62 int16_t idx;
63 char buf[256];
64 };
65
66 char __attribute__((tainted_args))
67 test_s16_field_256_elements (struct st_s16_field_256_elements s)
68 {
69 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
70 }
71
72 struct st_u16_field_256_elements
73 {
74 uint16_t idx;
75 char buf[256];
76 };
77
78 char __attribute__((tainted_args))
79 test_u16_field_256_elements (struct st_u16_field_256_elements s)
80 {
81 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
82 }
83
84 /* Attacker-controlled 16 bit values where the array is
85 big enough, but where the value might be signed. */
86
87 struct st_s16_field_65536_elements
88 {
89 int16_t idx;
90 char buf[65536];
91 };
92
93 char __attribute__((tainted_args))
94 test_s16_field_65536_elements (struct st_s16_field_65536_elements s)
95 {
96 return s.buf[s.idx]; /* { dg-warning "tainted-array-index" } */
97 }
98
99 struct st_u16_field_65536_elements
100 {
101 uint16_t idx;
102 char buf[65536];
103 };
104
105 char __attribute__((tainted_args))
106 test_u16_field_65536_elements (struct st_u16_field_65536_elements s)
107 {
108 return s.buf[s.idx]; /* { dg-bogus "tainted-array-index" } */
109 }