1*7c3d14c8STreehugger Robot // Test shadow faults during esan initialization as well as 2*7c3d14c8STreehugger Robot // faults during dlsym's calloc during interceptor init. 3*7c3d14c8STreehugger Robot // 4*7c3d14c8STreehugger Robot // RUN: %clang_esan_wset %s -o %t 5*7c3d14c8STreehugger Robot // RUN: %run %t 2>&1 | FileCheck %s 6*7c3d14c8STreehugger Robot 7*7c3d14c8STreehugger Robot #include <stdio.h> 8*7c3d14c8STreehugger Robot #include <stdlib.h> 9*7c3d14c8STreehugger Robot #include <string.h> 10*7c3d14c8STreehugger Robot 11*7c3d14c8STreehugger Robot // Our goal is to emulate an instrumented allocator, whose calloc 12*7c3d14c8STreehugger Robot // invoked from dlsym will trigger shadow faults, to test an 13*7c3d14c8STreehugger Robot // early shadow fault during esan interceptor init. 14*7c3d14c8STreehugger Robot // We do this by replacing calloc: calloc(size_t size,size_t n)15*7c3d14c8STreehugger Robotvoid *calloc(size_t size, size_t n) { 16*7c3d14c8STreehugger Robot // Unfortunately we can't print anything to make the test 17*7c3d14c8STreehugger Robot // ensure we got here b/c the sanitizer interceptors can't 18*7c3d14c8STreehugger Robot // handle that during interceptor init. 19*7c3d14c8STreehugger Robot 20*7c3d14c8STreehugger Robot // Ensure we trigger a shadow write fault: 21*7c3d14c8STreehugger Robot int x[16]; 22*7c3d14c8STreehugger Robot x[0] = size; 23*7c3d14c8STreehugger Robot // Now just emulate calloc. 24*7c3d14c8STreehugger Robot void *res = malloc(size*n); 25*7c3d14c8STreehugger Robot memset(res, 0, size*n); 26*7c3d14c8STreehugger Robot return res; 27*7c3d14c8STreehugger Robot } 28*7c3d14c8STreehugger Robot main(int argc,char ** argv)29*7c3d14c8STreehugger Robotint main(int argc, char **argv) { 30*7c3d14c8STreehugger Robot printf("all done\n"); 31*7c3d14c8STreehugger Robot return 0; 32*7c3d14c8STreehugger Robot } 33*7c3d14c8STreehugger Robot // CHECK: all done 34