diff options
author | Denis Khalikov <d.khalikov@partner.samsung.com> | 2017-12-19 12:47:55 +0300 |
---|---|---|
committer | Slava Barinov <v.barinov@samsung.com> | 2024-05-13 14:38:25 +0300 |
commit | 799b36a40f47d21727507f35f0b0c545509db083 (patch) | |
tree | 08e144e91f0b91e6343adcbe32e720320d5807d6 | |
parent | ec8a87f3443579919c721c9c63d0d0d48e105cb1 (diff) | |
download | gcc-799b36a40f47d21727507f35f0b0c545509db083.tar.gz gcc-799b36a40f47d21727507f35f0b0c545509db083.tar.bz2 gcc-799b36a40f47d21727507f35f0b0c545509db083.zip |
[ASan] Add tests of interceptor for printf_chk
Differential Revision: https://reviews.llvm.org/D40951
Change-Id: I7c32945659da4cf80e995370cb26fb063bb7930c
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/sprintf-fortify-1.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/vsnprintf-fortify-1.c | 38 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/vsprintf-fortify-1.c | 37 |
4 files changed, 133 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c b/gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c new file mode 100644 index 00000000000..b5e1a6e5101 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ +/* { dg-options "-D_FORTIFY_SOURCE=1 -w" } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O1" } } */ +/* { dg-shouldfail "asan" } */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +const char * +__asan_default_options () { + return "fast_unwind_on_malloc=false"; +} + +#ifdef __cplusplus +} +#endif + +int main(int argc, char **argv) { + char *short_buffer = (char*)malloc(3); + snprintf (short_buffer, 10, "%s_%s", "hello", "world"); /* BOOM */ + return short_buffer[0]; +} +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)__snprintf_chk|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ + diff --git a/gcc/testsuite/gcc.dg/asan/sprintf-fortify-1.c b/gcc/testsuite/gcc.dg/asan/sprintf-fortify-1.c new file mode 100644 index 00000000000..86fed28e373 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/sprintf-fortify-1.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ +/* { dg-options "-D_FORTIFY_SOURCE=1 -w" } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O1" } } */ +/* { dg-shouldfail "asan" } */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +const char * +__asan_default_options () { + return "fast_unwind_on_malloc=false"; +} + +#ifdef __cplusplus +} +#endif + +int main(int argc, char **argv) { + char *short_buffer = (char*)malloc(3); + sprintf (short_buffer, "%s_%s", "hello", "world"); /* BOOM */ + return short_buffer[0]; +} +/* { dg-output " #1 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)__sprintf_chk|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ + diff --git a/gcc/testsuite/gcc.dg/asan/vsnprintf-fortify-1.c b/gcc/testsuite/gcc.dg/asan/vsnprintf-fortify-1.c new file mode 100644 index 00000000000..711c31f84e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/vsnprintf-fortify-1.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-D_FORTIFY_SOURCE=1 -w" } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O1" } } */ +/* { dg-shouldfail "asan" } */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" { +#endif + +const char * +__asan_default_options () { + return "fast_unwind_on_malloc=false"; +} + +#ifdef __cplusplus +} +#endif + +__attribute__((noinline, noclone)) +char foo (const char *format, ...) { + char *str = (char *) malloc (1); + va_list ap; + va_start (ap, format); + vsnprintf (str, 10, format, ap); + va_end (ap); + return str[1]; +} + +int main(int argc, char **argv) { + return foo ("%s_%s", "hello", "world"); +} +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)__vsnprintf_chk|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ + diff --git a/gcc/testsuite/gcc.dg/asan/vsprintf-fortify-1.c b/gcc/testsuite/gcc.dg/asan/vsprintf-fortify-1.c new file mode 100644 index 00000000000..d14f38fff75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/vsprintf-fortify-1.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-D_FORTIFY_SOURCE=1 -w" } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O1" } } */ +/* { dg-shouldfail "asan" } */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" { +#endif + +const char * +__asan_default_options () { + return "fast_unwind_on_malloc=false"; +} + +#ifdef __cplusplus +} +#endif + +char foo (const char *format, ...) { + char *str = (char *) malloc (1); + va_list ap; + va_start (ap, format); + vsprintf (str, format, ap); + va_end (ap); + return str[1]; +} + +int main(int argc, char **argv) { + return foo ("%s_%s", "hello", "world"); +} +/* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)__vsprintf_chk|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ + |