Compile and Using MariaDB with AddressSanitizer (ASAN)
What is AddressSanitizer (ASAN)
- Use after free (dangling pointer dereference)
- Heap buffer overflow
- Stack buffer overflow
- Global buffer overflow
- Use after return
- Use after scope
- Initialization order bugs
- Memory leaks
To use ASAN you need a gcc version that supports ASAN. gcc 4.8.5 and up are known to work.
How to Compile MariaDB for ASAN
ASAN is supported in MariaDB 10.1 and up.
You can use one of the two following build commands:
cmake . -DWITH_ASAN=ON
or from MariaDB 10.2 and up:
Running an ASAN Build
To run mysqld with instrumentation you have to set the
ASAN_OPTIONS environment variable before starting
mysqld. Either in your shell or in your mysqld_safe script.
The above command will abort any instrumented executable if any errors are found, which is good for debugging. If you set abort_on_error=0 all server errors are logged to your error log file (mysqld.err).
To catch errors for other processes than the server, you can set more options, like this:
If you are seeing an incomplete stack trace for a memory allocation, you may rerun the failing test with
To get core dumps of failures:
To see all the options (or to check if an executable is instrumented), you may try the following:
ASAN_OPTIONS=help=1 extra/perror 0
The MariaDB test system can use Valgrind for finding memory leaks and wrong memory accesses. Valgrind is an instrumentation framework for building dynamic analysis tools. If Valgrind is installed on your system, you can simply use mysql-test-run --valgrind to run the test under Valgrind.