C/C++
Supported frameworks and package managers
Code analysis
Snyk Code supports the following:
Operating systems
Linux
Windows (limited)
Embedded systems: Linux
GUI Framework
Libraries: POSIX, C++ Standard Library, Boost, Qt (limited)
Open source and licensing
Open source policy
To manage licenses from your developer workflows through policy, see the following topics:
Package managers / Features | CLI support | Git support | License scanning | Fix PRs |
---|---|---|---|---|
C/C++ | ✔︎ | ✔︎ |
Open source license compliance
To check compliance for open source licenses, see Getting Started with Snyk License Compliance Management.
Getting started with Snyk for C/C++ across environments
Scans are powered by an open source database, periodically updated with the latest source code from online sources.
To navigate through the vulnerabilities for C/C++, use the Snyk Vuln DB.
When you run the snyk test --unmanaged
command, Snyk does the following:
Converts all files from your current folder into a list of hashes.
Sends hashes to the Snyk scan server to compute the dependencies list.
Queries the database to find a list of potentially matching dependencies.
Links the dependencies to the known vulnerabilities.
Displays the results.
For Snyk to scan the Project, the dependencies must be available as source code in the scanned directory. If the dependencies are in a different location, that location must be scanned.
Scanning archives
By default, archives are not scanned. However, Snyk CLI can recursively extract archives to analyze the source code inside.
To enable archive extraction, specify the depth of the extraction using the --max-depth
option.
The supported archive formats are:
zip-like archives
tar archives
tar with gzip compression algorithm
Constraints and limitations
The following constraints and limitations are by design. While Snyk may work on improvements in the future, they are not considered an issue.
Source code dependencies need to be available in the scanned folder
For Snyk CLI to be able to find dependencies in your source code, enough of the full dependencies source code needs to be present in the scanned folder.
Having a large percentage of files in their original (unchanged) form is critical to accurately identifying dependencies and reporting the correct set of vulnerabilities back. Modifying that source code reduces the confidence of the scanning engine, resulting in less accurate results. Other potential issues could include dependencies not being identified or being identified incorrectly, as a different version or even a different package.
The example that follows shows a typical package with dependencies listed:
Data collection note
When you scan C++ Projects, the following data is collected and may be stored for troubleshooting purposes:
Hashes of the scanned files: All files are converted to a list of irreversible hashes.
Relative paths to scanned files: The paths to files relative to the directory being scanned are included for better identification and matching.
Example:
./project-name/vendor/bzip2-1.0.6/blocksort.c
Snyk CLI
Prerequisites
Set the default Organization for all Snyk tests (code analysis)
Code analysis
To start testing your code using Snyk Code open your repository in a terminal and run the following command:
To customize test options, run other commands, exclude directories and files, and explore the results in different formats, see the following:
Open source and licensing
Run the test
To test your Project for vulnerabilities, run the following:
Displaying dependencies
To display dependencies, use the --print-deps
option:
To learn what files contributed to each dependency being identified, use the --print-dep-paths
option:
Understanding the confidence level
You may need to change the source code of the dependencies that you use in your software. As Snyk uses file signatures to find the closest possible match to an open-source library, your changes may decrease the accuracy of the identification of the actual library.
To learn how confident Snyk is about the identified dependency and its version, use the --print-deps
or --print-dep-paths
command line option:
This confidence level shows how confident Snyk is about the actual identification of the dependency. The number can be between 0 and 1 and the higher it is, the more accurate the identification is. Thus a confidence of 1 means that all the files in the source tree fully matched all the expected files in the Snyk database.
JSON output
To get a machine-readable output in JSON, use the --json
option:
Command line options
The following snyk
command line options are supported with the snyk test --unmanaged
and snyk monitor --unmanaged
commands:
--org=<ORG_ID>
--json
--json-file-output=<OUTPUT_FILE_PATH>
(snyk test
only)
--remote-repo-url=<URL>
--severity-threshold=<low|medium|high|critical>
(snyk test
only)
--max-depth
--print-dep-paths
--target-reference=<TARGET_REFERENCE>
(snyk monitor
only)
--project-name=<c-project>
(snyk monitor
only)
For more information about command line options, see the Snyk help docs: Options for scanning with snyk test --unmanaged
or snyk monitor --unmanaged
.
To import the test results (issues and dependencies) in the Snyk CLI, run the snyk monitor --unmanaged
command:
This creates a snapshot of dependencies and vulnerabilities and imports them into the Snyk Web UI, where you can review the issues and see them included in your reports.
Importing a Project with unmanaged dependencies creates a new Project:
Snyk Web UI supports only code analysis, using Snyk Code.
Snyk integrations
Snyk Code
No additional options are required. The Snyk plugin has views within the IDE for displaying results.
Snyk Open Source
Under Additional Parameters in the IDE settings, enter the --unmanaged option to scan for C/C++ open source dependencies.
Help
🔗 See best practices and troubleshooting.
Last updated