介绍地址消毒.
Background
For a business software, minimal error may lead critical issue in production environment. In the company’s projects, we utilize address sanitization to identify potential issues, thereby enhancing the reliability of the program.
Introduction
AddressSanitizer (aka ASan) is a memory error detector for C/C++.
Practice
cat test_asan.c
#include <stdlib.h>
#include <string.h>
int test_use_after_free()
{
char *x = (char*)malloc(10 * sizeof(char));
free(x);
return x[5];
}
void test_stack_overflow()
{
char buf[10] = {0};
memset(buf, 0, 20);
}
int main()
{
test_use_after_free();
test_stack_overflow();
return 0;
}
Compile with ASan:
g++ -o bin_asan -g test_asan.c -fsanitize=address
./bin_asan
Comments