brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 5389797 Raw
53 lines · cpp
1// RUN: %clangxx_msan %s -o %t2// RUN: %run %t --disable-checks 0 2>&1 | FileCheck --check-prefix=DISABLED --allow-empty %s3// RUN: %run %t --disable-checks 1 2>&1 | FileCheck --check-prefix=DISABLED --allow-empty %s4// RUN: %run %t --disable-checks 2 2>&1 | FileCheck --check-prefix=DISABLED --allow-empty %s5// RUN: %run %t --disable-checks 3 2>&1 | FileCheck --check-prefix=DISABLED --allow-empty %s6// RUN: not %run %t --reenable-checks 0 2>&1 | FileCheck --check-prefix=CASE-0 %s7// RUN: not %run %t --reenable-checks 1 2>&1 | FileCheck --check-prefix=CASE-1 %s8// RUN: not %run %t --reenable-checks 2 2>&1 | FileCheck --check-prefix=CASE-2 %s9// RUN: not %run %t --reenable-checks 3 2>&1 | FileCheck --check-prefix=CASE-3 %s10 11#include <assert.h>12#include <stdio.h>13#include <stdlib.h>14#include <string.h>15#include <sanitizer/msan_interface.h>16 17int main(int argc, char *argv[]) {18  assert(argc == 3);19  __msan_scoped_disable_interceptor_checks();20  if (strcmp(argv[1], "--reenable-checks") == 0)21    __msan_scoped_enable_interceptor_checks();22 23  char uninit[7];24  switch (argv[2][0]) {25    case '0': {26      char *copy = strndup(uninit, sizeof(uninit));  // BOOM27      free(copy);28      break;29      // CASE-0: Uninitialized bytes in strndup30    }31    case '1': {32      puts(uninit);  // BOOM33      puts(uninit);  // Ensure previous call did not enable interceptor checks.34      break;35      // CASE-1: Uninitialized bytes in puts36    }37    case '2': {38      int cmp = memcmp(uninit, uninit, sizeof(uninit));  // BOOM39      break;40      // CASE-2: Uninitialized bytes in MemcmpInterceptorCommon41    }42    case '3': {43      size_t len = strlen(uninit);  // BOOM44      break;45      // CASE-3: Uninitialized bytes in strlen46    }47    default: assert(0);48  }49  // DISABLED-NOT: Uninitialized bytes50  return 0;51}52 53