Debian Codegraph @

gcc/testsuite/c-c++-common/asan/strncpy-overflow-1.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-fno-builtin-malloc -fno-builtin-strncpy" } */
3 /* { dg-additional-options "-D_FORTIFY_SOURCE=0 -gdwarf-3" { target *-*-darwin* } } */
4 /* { dg-shouldfail "asan" } */
5
6 #include <string.h>
7 #include <stdlib.h>
8 int main(int argc, char **argv) {
9 char *hello = (char*)malloc(6);
10 strcpy(hello, "hello");
11 char *short_buffer = (char*)malloc(9);
12 strncpy(short_buffer, hello, 10); /* BOOM */
13 return short_buffer[8];
14 }
15
16 /* { dg-output "WRITE of size \[0-9\]* at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */
17 /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)strncpy|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
18 /* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:12|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\]).*(\n|\r\n|\r)" } */
19 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes after 9-byte region\[^\n\r]*(\n|\r\n|\r)" } */
20 /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
21 /* { dg-output " #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
22 /* { dg-output " #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:11|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */