start-deactivated.cc [plain text]
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string>
#include "sanitizer/asan_interface.h"
void test_malloc_shadow() {
char *p = (char *)malloc(100);
char *q = (char *)__asan_region_is_poisoned(p + 95, 8);
fprintf(stderr, "=%zd=\n", q ? q - (p + 95) : -1);
free(p);
}
typedef void (*Fn)();
int main(int argc, char *argv[]) {
test_malloc_shadow();
std::string path = std::string(argv[0]) + "-so.so";
void *dso = dlopen(path.c_str(), RTLD_NOW);
if (!dso) {
fprintf(stderr, "dlopen failed: %s\n", dlerror());
return 1;
}
test_malloc_shadow();
void *fn = dlsym(dso, "do_another_bad_thing");
if (!fn) {
fprintf(stderr, "dlsym failed: %s\n", dlerror());
return 1;
}
((Fn)fn)();
return 0;
}