1// Make sure the zones created by malloc_create_zone() are write-protected.
2#include <malloc/malloc.h>
3#include <stdio.h>
4
5// RUN: %clangxx_asan %s -o %t
6// RUN: ASAN_OPTIONS="abort_on_error=1" not --crash %run %t 2>&1 | FileCheck %s
7
8
9void *pwn(malloc_zone_t *unused_zone, size_t unused_size) {
10 printf(format: "PWNED\n");
11 return NULL;
12}
13
14int main() {
15 malloc_zone_t *zone = malloc_create_zone(0, 0);
16 zone->malloc = pwn;
17 void *v = malloc_zone_malloc(zone, 1);
18 // CHECK-NOT: PWNED
19 return 0;
20}
21

source code of compiler-rt/test/asan/TestCases/Darwin/malloc_zone-protected.cpp