ashiba
ashiba

Reputation: 131

How to use poisoning function of address sanitizer with ASAN_POISON_MEMORY_REGION macro (at clang++)?

Now, I'm trying to use poisoning function of Address Sanitizer at clang++ compiler. I thought I should use ASAN_POISON_MEMORY_REGION macro according to this description(https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning). And then, I wrote a brief program like below.

int main() {
    int* data = new int[10];

    // poisoning from data[5] to data[9]
    ASAN_POISON_MEMORY_REGION(data+5, sizeof(int)*5);

    for (int i=0; i<=5; ++i) {
        data[i] = i;
    }
}

But compiler says error: use of undeclared identifier 'ASAN_POISON_MEMORY_REGION' and not working.

Next, I add #include <sanitizer/asan_interface.h> as a header. But It also doesn't worked correctly(with error fatal error: 'sanitizer/asan_interface.h' file not found ).

Do I have to do something setting? or include another header?

Upvotes: 3

Views: 3247

Answers (2)

Anna
Anna

Reputation: 49

It's looks like your clang++ doesn't contain address sanitizer. Try to use another compiler or check if compiler-rt exist in your current compiler.

Also maybe you need to update your LDFLAGS with clang++ paths.

Upvotes: 1

ashiba
ashiba

Reputation: 131

This is the questioner's own answer.

Adding #include <sanitizer/asan_interface.h> is needed for using ASAN_POISON_MEMORY_REGION. You can include it by installing compiler-rt.

Upvotes: 2

Related Questions