brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 1ceaa50 Raw
39 lines · c
1// RUN: %clang_safestack -fno-stack-protector -D_FORTIFY_SOURCE=0 -g %s -o %t.nossp2// RUN: %run %t.nossp 2>&1 | FileCheck --check-prefix=NOSSP %s3 4// RUN: %clang_safestack -fstack-protector-all -D_FORTIFY_SOURCE=0 -g %s -o %t.ssp5// RUN: env LIBC_FATAL_STDERR_=1 not --crash %run %t.ssp 2>&1 | \6// RUN:     FileCheck -check-prefix=SSP %s7 8// Test stack canaries on the unsafe stack.9 10// REQUIRES: stable-runtime11 12#include <assert.h>13#include <stdio.h>14#include <string.h>15 16__attribute__((noinline)) void f(unsigned *y) {17  char x;18  char *volatile p = &x;19  char *volatile q = (char *)y;20  assert(p < q);21  assert(q - p < 1024); // sanity22  // This has technically undefined behavior, but we know the actual layout of23  // the unsafe stack and this should not touch anything important.24  memset(&x, 0xab, q - p + sizeof(*y));25}26 27int main(int argc, char **argv)28{29  unsigned y;30  // NOSSP: main 131  // SSP: main 132  fprintf(stderr, "main 1\n");33  f(&y);34  // NOSSP: main 235  // SSP-NOT: main 236  fprintf(stderr, "main 2\n");37  return 0;38}39