__asan_poison_memory_region不起作用

时间:2018-04-25 08:04:49

标签: gcc address-sanitizer

我正在尝试AddressSanitizer的#include <stdlib.h> #include <stdio.h> void __asan_poison_memory_region(void *p, int n); void unit_test_2(void) { int *p; p = (int *)malloc(sizeof(int)); __asan_poison_memory_region(p, sizeof(int)); *p = 1; printf("%p:%d\n", p, *p); return; } 功能。这是一个简单的复制者:

==32232==AddressSanitizer Init done
Trying to poison memory region [0x00000147a040, 0x00000147a044)
0x147a040:1

ASAN的调试日志说

__asan_poison_memory_region

ASAN试图毒害内存,但保护措施不起作用:数据被错误地写入中毒地址,而不是报告无效访问。

我误解了BodyStyle = WebMessageBodyStyle.WrappedRequest或遗漏了什么吗?

1 个答案:

答案 0 :(得分:0)

您被Asan FAQ中的以下项目点击:

Q: Why didn't ASan report an obviously invalid memory access in my code?

A1: If your errors is too obvious, compiler might have already optimized
    it out by the time Asan runs.

如果查看汇编代码,您会看到编译器常量传播的赋值为*pprintf调用:

mov DWORD PTR [rbx], 1
mov rsi, rbx
mov edx, 1
pop rbx
mov edi, OFFSET FLAT:.LC0
xor eax, eax
jmp printf