summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/asan/snprintf-fortify-1.c29
1 files changed, 29 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)" } */
+