145
|
1 /* PR middle-end/91582 - missing heap overflow detection for strcpy
|
|
2 Verify calls via function pointers.
|
|
3 { dg-do compile }
|
|
4 { dg-options "-O2 -Wall -Wno-array-bounds -ftrack-macro-expansion=0" } */
|
|
5
|
|
6 typedef __attribute__ ((alloc_size (1))) char* allocfn_t (unsigned);
|
|
7
|
|
8 extern allocfn_t allocfn;
|
|
9
|
|
10 void sink (void*);
|
|
11
|
|
12 void direct_call (void)
|
|
13 {
|
|
14 char *q = allocfn (0); // { dg-message "at offset 0 to an object with size 0 allocated by 'allocfn'" }
|
|
15 q[0] = 0; // { dg-warning "\\\[-Wstringop-overflow" }
|
|
16 sink (q);
|
|
17 }
|
|
18
|
|
19
|
|
20 void local_ptr_call (void)
|
|
21 {
|
|
22 allocfn_t *ptr = allocfn;
|
|
23 char *q = ptr (1); // { dg-message "at offset -1 to an object with size 1 allocated by 'allocfn'" }
|
|
24 q[0] = 0;
|
|
25 q[-1] = 0; // { dg-warning "\\\[-Wstringop-overflow" }
|
|
26 sink (q);
|
|
27 }
|
|
28
|
|
29
|
|
30 void global_ptr_call (void)
|
|
31 {
|
|
32 extern allocfn_t *ptralloc;
|
|
33
|
|
34 allocfn_t *ptr = ptralloc;
|
|
35 char *q = ptr (2); // { dg-message "at offset 3 to an object with size 2 allocated by 'ptralloc'" }
|
|
36 q[0] = 0;
|
|
37 q[1] = 1;
|
|
38 q[3] = 3; // { dg-warning "\\\[-Wstringop-overflow" }
|
|
39 sink (q);
|
|
40 }
|
|
41
|
|
42 void global_ptr_array_call (void)
|
|
43 {
|
|
44 extern allocfn_t * (arralloc[]);
|
|
45
|
|
46 allocfn_t *ptr = arralloc[0];
|
|
47 char *q = ptr (2); // { dg-message "at offset 3 to an object with size 2 allocated by 'ptr'" }
|
|
48 q[0] = 1;
|
|
49 q[1] = 2;
|
|
50 q[3] = 3; // { dg-warning "\\\[-Wstringop-overflow" }
|
|
51 sink (q);
|
|
52 }
|
|
53
|
|
54
|
|
55 struct S { allocfn_t *ptralloc; };
|
|
56
|
|
57 void member_ptr_call (struct S *p)
|
|
58 {
|
|
59 char *q = p->ptralloc (3); // { dg-message "at offset 5 to an object with size 3 allocated by 'ptralloc' here" }
|
|
60 q[0] = 0;
|
|
61 q[1] = 1;
|
|
62 q[2] = 2;
|
|
63 q[5] = 0; // { dg-warning "\\\[-Wstringop-overflow" }
|
|
64 sink (q);
|
|
65 }
|
|
66
|