brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5aa087f Raw
48 lines · cpp
1// Check that malloc_default_zone and malloc_zone_from_ptr return the2// sanitizer-installed malloc zone even when MallocStackLogging (MSL) is3// requested. This prevents crashes in certain situations. Note that the4// sanitizers and MSL cannot be used together. If both are enabled, MSL5// functionality is essentially deactivated since it only hooks the default6// allocator which is replaced by a custom sanitizer allocator.7//8// MSL=lite creates its own special malloc zone, copies the passed zone name,9// and leaks it.10// RUN: echo "leak:create_and_insert_msl_lite_zone" >> lsan.supp11//12// RUN: %clangxx -g %s -o %t13// RUN:                                                                   %run %t | FileCheck %s14// RUN: %env MallocStackLogging=lite LSAN_OPTIONS=suppressions=lsan.supp  %run %t | FileCheck %s15// RUN: %env MallocStackLogging=full                                      %run %t | FileCheck %s16//17// UBSan does not install a malloc zone.18// XFAIL: ubsan19//20// Currently fails on darwin/lsan21// XFAIL: darwin && lsan22 23#include <malloc/malloc.h>24#include <stdlib.h>25#include <stdio.h>26 27int main(void) {28  malloc_zone_t *default_zone = malloc_default_zone();29  printf("default zone name: %s\n", malloc_get_zone_name(default_zone));30// CHECK: default zone name: {{a|l|t}}san31 32  void *ptr1 = malloc(10);33  void *ptr2 = malloc_zone_malloc(default_zone, 10);34 35  malloc_zone_t* zone1 = malloc_zone_from_ptr(ptr1);36  malloc_zone_t* zone2 = malloc_zone_from_ptr(ptr2);37 38  printf("zone1: %d\n", zone1 == default_zone);39  printf("zone2: %d\n", zone2 == default_zone);40// CHECK: zone1: 141// CHECK: zone2: 142 43  free(ptr1);44  malloc_zone_free(zone2, ptr2);45 46  return 0;47}48