brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 0ad5595 Raw
43 lines · c
1// RUN: %clang_hwasan -g %s -o %t2// RUN: not %run %t 0 2>&1 | FileCheck %s3// RUN: not %run %t -33 2>&1 | FileCheck %s4// REQUIRES: pointer-tagging5 6#include <assert.h>7#include <setjmp.h>8#include <stdio.h>9#include <stdlib.h>10 11/* Testing longjmp/setjmp should test that accesses to scopes jmp'd over are12   caught.  */13int __attribute__((noinline))14uses_longjmp(int **other_array, int num, jmp_buf env) {15  int internal_array[100] = {0};16  *other_array = &internal_array[0];17  longjmp(env, num);18}19 20int __attribute__((noinline)) uses_setjmp(int num) {21  int big_array[100];22  int *other_array = NULL;23  sigjmp_buf cur_env;24  int temp = 0;25  if ((temp = sigsetjmp(cur_env, 1)) != 0) {26    assert((num == 0 && temp == 1) || (num != 0 && temp == num));27    // We're testing that our longjmp interceptor untagged the previous stack.28    // Hence the tag in memory should be zero.29    if (other_array != NULL)30      return other_array[0];31    // CHECK: READ of size 4 at{{.*}}tags: {{..}}/0032    return 100;33  } else34    return uses_longjmp(&other_array, num, cur_env);35}36 37int __attribute__((noinline)) main(int argc, char *argv[]) {38  assert(argc == 2);39  int longjmp_retval = atoi(argv[1]);40  uses_setjmp(longjmp_retval);41  return 0;42}43