Home | History | Annotate | Download | only in output_tests
      1 #include <string.h>
      2 #include <stdlib.h>
      3 int main(int argc, char **argv) {
      4   char *hello = (char*)malloc(6);
      5   strcpy(hello, "hello");
      6   char *short_buffer = (char*)malloc(9);
      7   strncpy(short_buffer, hello, 10);  // BOOM
      8   return short_buffer[8];
      9 }
     10 
     11 // Check-Common: {{WRITE of size 1 at 0x.* thread T0}}
     12 // Check-Linux: {{    #0 0x.* in strncpy}}
     13 // Check-Darwin: {{    #0 0x.* in wrap_strncpy}}
     14 // Check-Common: {{    #1 0x.* in main .*strncpy-overflow.cc:[78]}}
     15 // Check-Common: {{0x.* is located 0 bytes to the right of 9-byte region}}
     16 // Check-Common: {{allocated by thread T0 here:}}
     17 
     18 // Check-Linux: {{    #0 0x.* in malloc}}
     19 // Check-Linux: {{    #1 0x.* in main .*strncpy-overflow.cc:6}}
     20 
     21 // Check-Darwin: {{    #0 0x.* in .*mz_malloc.*}}
     22 // Check-Darwin: {{    #1 0x.* in malloc_zone_malloc.*}}
     23 // Check-Darwin: {{    #2 0x.* in malloc.*}}
     24 // Check-Darwin: {{    #3 0x.* in main .*strncpy-overflow.cc:6}}
     25