This guide explains how to apply CMASan to a new application. The overall workflow consists of the following steps:
- Writing a build script
- Building a CodeQL database
- Generating the CMA list (CMA Identification)
- Building the application
- Running the instrumented application
CMASan provides template scripts for common build systems under benchmark/scripts/templates.
(If you've suffered from complex build setups with other sanitizer-based tools, feel free to reuse these in your project.)
Supported build systems:
- CMake/Make (
cmake.sh) - Bazel (
bazel.sh) - SCons (
scons.sh) - C/C++ Python Extension (
on_python.sh)
Use these templates to write a build script for your application and place it under:
benchmark/scripts/<your_application_name>.sh
(If you already have a known list of CMA APIs, skip this process)
Run the following command to generate a CodeQL database:
codeql database create $(pwd)/db/<your_application_name> \
--language=c-cpp \
--command="$(pwd)/scripts/run_in_codeql.sh <your_application_name>" \
--overwrite \
--source-root=/ \
-j$(nproc)For more information, refer to the official CodeQL documentation.
If you have a known list of CMA APIs, create a text file listing each function location on a separate line in the format <filepath>:<begin>, and manually annotate them using:
python3 scripts/cma-identification/annotate.py -t <your application name> -i <your cma list location>Otherwise, you can use our helper script to identify candidate CMA APIs semi-automatically with your response:
python3 scripts/cma-identification/analyze.py -t <your application name>Annotation or Identification script will generate a CMA list at: ./<your_application_name>.json
Check out the generated JSON and move them into benchmark/cma_list
Run the build script you prepared in Step 1:
./scripts/<your_application_name>Run the following script to test the instrumented application:
./result/<your_application_name>/single_run.shOr, load the test environment manually and run commands interactively:
source ./result/<your_application_name>/test_env