2017-04-21 2 views
1

아래 코드를 고려하십시오. 주소 소독자로 컴파일하고 실행할 때 오류가 표시되지 않습니다. 하지만 오류 즉, 경계 메모리 위치를 지정/액세스하는 중 오류가 발생해야합니까? 살균제가 그것을 감지하지 못하는 이유는 무엇입니까?주소 소독제가 거짓인가?

int arr[30]; 

int main(){ 
    arr[40] = 34; 
    printf(“%d”, arr[40]); 
} 

고마워요!

clang -fsanitize=address -fno-omit-frame-pointer test.c 
./a.out 

답변

2

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. 

A2: Another, C-only option is accesses to global common symbols which are 
    not protected by Asan (you can use -fno-common to disable generation of 
    common symbols and hopefully detect more bugs). 
+0

하지만 INT의 편곡을 할 경우에도 [30] 지방 대신 글로벌, 그것은 오류가 발생하지 않습니다. -fno-common을 사용해도 오류가 발생하지 않습니다. –

+0

물론 그 대답은 A1에 관한 것입니다. 기본적으로 GCC 프론트 엔드는 ASan이 개입 할 수 있기 전에 일찍 명백하게 나쁜 액세스를 버릴 정도로 "똑똑"합니다. – yugr