111
|
1 /* PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow
|
|
2 warnings
|
|
3 { dg-do compile }
|
|
4 { dg-options "-O2" } */
|
|
5
|
|
6 #include "pr79214.h"
|
|
7
|
|
8 typedef __SIZE_TYPE__ size_t;
|
|
9
|
|
10 char d[3];
|
|
11 char s[4];
|
|
12
|
131
|
13 static size_t range (void)
|
111
|
14 {
|
|
15 extern size_t size ();
|
|
16 size_t n = size ();
|
|
17 if (n <= sizeof d)
|
|
18 return sizeof d + 1;
|
|
19
|
|
20 return n;
|
|
21 }
|
|
22
|
|
23 void test_bzero (void)
|
|
24 {
|
|
25 bzero (d, range ()); /* { dg-warning ".__builtin_(bzero|memset). writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
26 }
|
|
27
|
|
28 void test_memcpy (void)
|
|
29 {
|
|
30 memcpy (d, s, range ()); /* { dg-warning ".__builtin_memcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
31 }
|
|
32
|
|
33 void test_memmove (void)
|
|
34 {
|
|
35 memmove (d, d + 1, range ()); /* { dg-warning ".__builtin_memmove. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
36 }
|
|
37
|
|
38 void test_mempcpy (void)
|
|
39 {
|
|
40 mempcpy (d, s, range ()); /* { dg-warning ".__builtin_mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
41 }
|
|
42
|
|
43 void test_memset (int n)
|
|
44 {
|
|
45 memset (d, n, range ()); /* { dg-warning ".__builtin_memset. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
46 }
|
|
47
|
|
48 void test_strcat (int i)
|
|
49 {
|
|
50 const char *s = i < 0 ? "123" : "4567";
|
|
51
|
|
52 strcat (d, s); /* { dg-warning ".__builtin_strcat. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
|
|
53 }
|
|
54
|
|
55 char* test_stpcpy (int i)
|
|
56 {
|
|
57 const char *s = i < 0 ? "123" : "4567";
|
|
58
|
|
59 return stpcpy (d, s); /* { dg-warning ".__builtin_stpcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
|
|
60 }
|
|
61
|
|
62 char* test_stpncpy (int i)
|
|
63 {
|
|
64 const char *s = i < 0 ? "123" : "4567";
|
|
65
|
|
66 return stpncpy (d, s, range ()); /* { dg-warning ".__builtin_stpncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
67 }
|
|
68
|
|
69 char* test_strcpy (int i)
|
|
70 {
|
|
71 const char *s = i < 0 ? "123" : "4567";
|
|
72
|
|
73 return strcpy (d, s); /* { dg-warning ".__builtin_strcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
|
|
74 }
|
|
75
|
|
76 char* test_strncpy (int i)
|
|
77 {
|
|
78 const char *s = i < 0 ? "123" : "4567";
|
|
79
|
|
80 return strncpy (d, s, range ()); /* { dg-warning ".__builtin_strncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
|
|
81 }
|
|
82
|
|
83 char* test_strncat (int i)
|
|
84 {
|
|
85 const char *s = i < 0 ? "123" : "4567";
|
|
86
|
|
87 return strncat (d, s, range ()); /* { dg-warning ".__builtin_strncat. specified bound between 4 and \[0-9\]+" } */
|
|
88 }
|