diff options
author | Martin Sebor <msebor@redhat.com> | 2017-05-04 20:54:43 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-05-04 14:54:43 -0600 |
commit | e50d56a502c1140502e498942a739953e85edf1f (patch) | |
tree | 052b919e3dc3dfdaf0c430202ec00ab03681aa7a /gcc/testsuite | |
parent | 0f05d90543023e62bb272e6d97d0de3ddc32ab30 (diff) | |
download | gcc-e50d56a502c1140502e498942a739953e85edf1f.zip gcc-e50d56a502c1140502e498942a739953e85edf1f.tar.gz gcc-e50d56a502c1140502e498942a739953e85edf1f.tar.bz2 |
PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow warnings
PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow warnings
PR middle-end/79222 - missing -Wstringop-overflow= on a stpcpy overflow
PR middle-end/79223 - missing -Wstringop-overflow on a memmove overflow
gcc/ChangeLog:
PR preprocessor/79214
PR middle-end/79222
PR middle-end/79223
* builtins.c (check_sizes): Add inlinining context and issue
warnings even when -Wno-system-headers is set.
(check_strncat_sizes): Same.
(expand_builtin_strncat): Same.
(expand_builtin_memmove): New function.
(expand_builtin_stpncpy): Same.
(expand_builtin): Handle memmove and stpncpy.
gcc/testsuite/ChangeLog:
PR preprocessor/79214
PR middle-end/79222
PR middle-end/79223
* gcc.dg/pr79214.c: New test.
* gcc.dg/pr79214.h: New test header.
* gcc.dg/pr79222.c: New test.
* gcc.dg/pr79223.c: New test.
* gcc.dg/pr78138.c: Adjust.
* gfortran.dg/unconstrained_commons.f: Same.
From-SVN: r247618
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr78138.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr79214.c | 88 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr79214.h | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr79222.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr79223.c | 37 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/unconstrained_commons.f | 1 |
7 files changed, 165 insertions, 1 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a4d3c32..89ed4db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,17 @@ 2017-05-04 Martin Sebor <msebor@redhat.com> + PR preprocessor/79214 + PR middle-end/79222 + PR middle-end/79223 + * gcc.dg/pr79214.c: New test. + * gcc.dg/pr79214.h: New test header. + * gcc.dg/pr79222.c: New test. + * gcc.dg/pr79223.c: New test. + * gcc.dg/pr78138.c: Adjust. + * gfortran.dg/unconstrained_commons.f: Same. + +2017-05-04 Martin Sebor <msebor@redhat.com> + PR translation/80280 * g++.dg/abi/Wabi-2-3.C: Adjust. * g++.dg/abi/Wabi-3-2.C: Ditto. diff --git a/gcc/testsuite/gcc.dg/pr78138.c b/gcc/testsuite/gcc.dg/pr78138.c index 6129c91..5145cb4 100644 --- a/gcc/testsuite/gcc.dg/pr78138.c +++ b/gcc/testsuite/gcc.dg/pr78138.c @@ -20,5 +20,5 @@ void g (void *p) extern unsigned n; if (n < 17 || 32 < n) n = 7; - memcpy (d, p, n); /* { dg-warning ".memcpy.: writing between 7 and 32 bytes into a region of size 5" } */ + memcpy (d, p, n); /* { dg-warning ".memcpy. writing between 7 and 32 bytes into a region of size 5" } */ }; diff --git a/gcc/testsuite/gcc.dg/pr79214.c b/gcc/testsuite/gcc.dg/pr79214.c new file mode 100644 index 0000000..fbdecf4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79214.c @@ -0,0 +1,88 @@ +/* PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow + warnings + { dg-do compile } + { dg-options "-O2" } */ + +#include "pr79214.h" + +typedef __SIZE_TYPE__ size_t; + +char d[3]; +char s[4]; + +size_t range (void) +{ + extern size_t size (); + size_t n = size (); + if (n <= sizeof d) + return sizeof d + 1; + + return n; +} + +void test_bzero (void) +{ + bzero (d, range ()); /* { dg-warning ".__builtin_bzero. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_memcpy (void) +{ + memcpy (d, s, range ()); /* { dg-warning ".__builtin_memcpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_memmove (void) +{ + memmove (d, d + 1, range ()); /* { dg-warning ".__builtin_memmove. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_mempcpy (void) +{ + mempcpy (d, s, range ()); /* { dg-warning ".__builtin_mempcpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_memset (int n) +{ + memset (d, n, range ()); /* { dg-warning ".__builtin_memset. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_strcat (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + strcat (d, s); /* { dg-warning ".__builtin_strcat. writing 4 bytes into a region of size 3 overflows the destination" } */ +} + +char* test_stpcpy (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + return stpcpy (d, s); /* { dg-warning ".__builtin_stpcpy. writing 4 bytes into a region of size 3 overflows the destination" } */ +} + +char* test_stpncpy (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + return stpncpy (d, s, range ()); /* { dg-warning ".__builtin_stpncpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +char* test_strcpy (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + return strcpy (d, s); /* { dg-warning ".__builtin_strcpy. writing 4 bytes into a region of size 3 overflows the destination" } */ +} + +char* test_strncpy (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + return strncpy (d, s, range ()); /* { dg-warning ".__builtin_strncpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +char* test_strncat (int i) +{ + const char *s = i < 0 ? "123" : "4567"; + + return strncat (d, s, range ()); /* { dg-warning ".__builtin_strncat.: specified bound between 4 and \[0-9\]+" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr79214.h b/gcc/testsuite/gcc.dg/pr79214.h new file mode 100644 index 0000000..1481681 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79214.h @@ -0,0 +1,13 @@ +#pragma GCC system_header + +#define bzero __builtin_bzero +#define memcpy __builtin_memcpy +#define memmove __builtin_memmove +#define mempcpy __builtin_mempcpy +#define memset __builtin_memset +#define strcat __builtin_strcat +#define stpcpy __builtin_stpcpy +#define stpncpy __builtin_stpncpy +#define strcpy __builtin_strcpy +#define strncpy __builtin_strncpy +#define strncat __builtin_strncat diff --git a/gcc/testsuite/gcc.dg/pr79222.c b/gcc/testsuite/gcc.dg/pr79222.c new file mode 100644 index 0000000..7483a5e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79222.c @@ -0,0 +1,13 @@ +/* PR middle-end/79222 - missing -Wstringop-overflow= on a stpcpy overflow + { dg-do compile } + { dg-options "-O2" } */ + +extern char* stpcpy (char*, const char*); + +char d[3]; + +char* f (int i) +{ + const char *s = i < 0 ? "01234567" : "9876543210"; + return stpcpy (d, s); /* { dg-warning ".stpcpy. writing 9 bytes into a region of size 3 overflows the destination" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr79223.c b/gcc/testsuite/gcc.dg/pr79223.c new file mode 100644 index 0000000..5bfb1d9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79223.c @@ -0,0 +1,37 @@ +/* PR middle-end/79223 - missing -Wstringop-overflow on a memmove overflow + { dg-do compile } + { dg-additional-options "-O2 -Wall -std=gnu99" } */ + +typedef __SIZE_TYPE__ size_t; + +extern void* memcpy (void*, const void*, size_t); +extern void* mempcpy (void*, const void*, size_t); +extern void* memmove (void*, const void*, size_t); + +char d[3]; +char s[4]; + +size_t range (void) +{ + extern size_t size (); + size_t n = size (); + if (n <= sizeof d) + return sizeof d + 1; + + return n; +} + +void test_memcpy (void) +{ + memcpy (d, s, range ()); /* { dg-warning ".memcpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_mempcpy (void) +{ + mempcpy (d, s, range ()); /* { dg-warning ".mempcpy. writing between 4 and \[0-9\]+ bytes into a region of size 3 overflows the destination" } */ +} + +void test_memmove (void) +{ + memmove (d + 1, d, range ()); /* { dg-warning ".memmove. writing between 4 and \[0-9\]+ bytes into a region of size 2 overflows the destination" } */ +} diff --git a/gcc/testsuite/gfortran.dg/unconstrained_commons.f b/gcc/testsuite/gfortran.dg/unconstrained_commons.f index bee67ab..cb84e7f 100644 --- a/gcc/testsuite/gfortran.dg/unconstrained_commons.f +++ b/gcc/testsuite/gfortran.dg/unconstrained_commons.f @@ -18,3 +18,4 @@ ! We should retain both a read and write of mycommon.x. ! { dg-final { scan-tree-dump-times " _\[0-9\]+ = mycommon\\.x\\\[_\[0-9\]+\\\];" 1 "dom2" } } ! { dg-final { scan-tree-dump-times " mycommon\\.x\\\[j?_\[0-9\]+\\\] = _\[0-9\]+;" 1 "dom2" } } +! { dg-prune-output "overflows the destination" } |