Skip to main content

OpenCV security analysis

Goal

Lear how to use Codee for Static Application Security Testing (SAST) and generate a SAST report for OpenCV.

Getting started

Make sure you have Codee installed and available on your machine and clone the OpenCV repository.

git clone https://github.com/opencv/opencv.git

Now navigate to the source code:

cd opencv

Walkthrough

1. Generate the compile_commands.json

The compile_commands.json can be obtained using CMake. Make sure to obtain a complete compilation of the project:

cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-B build \
-S . && \
make -C build

2. Run Codee SAST report

New feature

Running codee commands with the additional --db codee.db flag enables Incremental Static Analysis. This reduces runtime by storing analysis results and reusing them in subsequent analysis, reanalyzing only the source code that has changed.

To obtain Codee SAST results for the CWE standard execute the following command:

codee screening --sast --db codee.db

You should have obtained a result similar to this:

<...>

0 file analyses reused from cache, 1399 files analyzed from scratch
1399 target files, 49135 functions, 22849 loops, 621398 SLOCs successfully analyzed (16837 checkers) and 0 non-analyzed files in 1 h 34 m 31 s