Skip to content

Commit a23743d

Browse files
Add "Baseline" query suites for C/C++.
These are queries from MISRA, AUTOSAR, and CERT, that have been hand picked based on a few properties: - review of violation count for each rule on real projects - review of accuracy of each rule - subjective review of broad applicability across most projects - subjective review of severity of each rule The baseline rules have been divided into two categories, "style," and "safety." The choice of which is subjective, but as a general rule: - Rules that tend to report only erroneous cases are typically "safety." - Rules that tend to report patterns that obscure erroneous behavior are typically "style." - If alerts can be mitigated by simple changes, it's more likely "style." - If it is challenging for a human to spot the rule violation, it's more likely "safety." - If the rule is designed to enforce some kind of "good habits," not just fix an isolated it's more likely "style." - If the rule feels "opinionated" in some sense, it's more likely "style." - If it is difficult to decide whether a finding should be fixed or deviated, it is more likely "safety." - Unsurprisingly, if the rule is purely syntactic or related to naming, it's more likely "style." Some rules are in both suites -- for instance, rules that ban the use of 'goto' are conceivably both "style" and "safety." While goto is not erroneous in itself, and gotos are easy to spot during human review, it is typically not a simple task to refactor code to remove gotos, and it is difficult to decide when a goto serves a legitimate purpose and the rule should be deviated. In general, the 'style' suites have more violations which are easier to fix, and the 'safety' suites have fewer violation that are harder to fix but warrant more attention to address. Project authors can therefore enable both with the 'default' suite, or pick between the two kinds suitable for their project and goals.
1 parent 682834c commit a23743d

File tree

417 files changed

+570
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+570
-2
lines changed

.codeqlmanifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"provide": [
3+
"cpp/baseline_suites/qlpack.yml",
34
"cpp/*/src/qlpack.yml",
45
"cpp/*/test/qlpack.yml",
6+
"c/baseline_suites/qlpack.yml",
57
"c/*/src/qlpack.yml",
68
"c/*/test/qlpack.yml",
79
"scripts/generate_modules/queries/qlpack.yml"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies:
4+
codeql/cpp-all:
5+
version: 4.0.3
6+
codeql/dataflow:
7+
version: 2.0.3
8+
codeql/mad:
9+
version: 1.0.19
10+
codeql/rangeanalysis:
11+
version: 1.0.19
12+
codeql/ssa:
13+
version: 1.0.19
14+
codeql/tutorial:
15+
version: 1.0.19
16+
codeql/typeflow:
17+
version: 1.0.19
18+
codeql/typetracking:
19+
version: 2.0.3
20+
codeql/util:
21+
version: 2.0.6
22+
codeql/xml:
23+
version: 1.0.19
24+
compiled: false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- description: C Baseline Coding Standards Queries
2+
- qlpack: codeql/cert-c-coding-standards
3+
- qlpack: codeql/misra-c-coding-standards
4+
- include:
5+
kind:
6+
- problem
7+
- path-problem
8+
tags contain:
9+
- coding-standards/baseline/safety
10+
- coding-standards/baseline/style
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- description: C Baseline Safety Coding Standards Queries
2+
- qlpack: codeql/misra-c-coding-standards
3+
- include:
4+
kind:
5+
- problem
6+
- path-problem
7+
tags contain:
8+
- coding-standards/baseline/safety
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- description: C Baseline Style Coding Standards Queries
2+
- qlpack: codeql/coding-standards-c-baseline
3+
- include:
4+
kind:
5+
- problem
6+
- path-problem
7+
tags contain:
8+
- coding-standards/baseline/style

c/baseline_suites/qlpack.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: codeql/coding-standards-c-baseline
2+
version: 2.49.0-dev
3+
description: A set of baseline coding standards for C projects, combining hand picked rules from MISRA C and CERT C.
4+
suites: codeql-suites
5+
license: MIT
6+
default-suite-file: codeql-suites/c-baseline-default.qls
7+
dependencies:
8+
codeql/misra-c-coding-standards: 2.49.0-dev
9+
codeql/cert-c-coding-standards: 2.49.0-dev

c/cert/src/rules/ARR32-C/VariableLengthArraySizeNotInValidRange.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* external/cert/priority/p6
1616
* external/cert/level/l2
1717
* external/cert/obligation/rule
18+
* coding-standards/baseline/safety
1819
*/
1920

2021
import cpp

c/cert/src/rules/ARR36-C/DoNotRelatePointersThatDoNotReferToTheSameArray.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* external/cert/priority/p8
1515
* external/cert/level/l2
1616
* external/cert/obligation/rule
17+
* coding-standards/baseline/safety
1718
*/
1819

1920
import cpp

c/cert/src/rules/CON30-C/CleanUpThreadSpecificStorage.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* external/cert/priority/p4
1616
* external/cert/level/l3
1717
* external/cert/obligation/rule
18+
* coding-standards/baseline/safety
1819
*/
1920

2021
import cpp

c/cert/src/rules/CON31-C/DoNotAllowAMutexToGoOutOfScopeWhileLocked.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* external/cert/priority/p4
1616
* external/cert/level/l3
1717
* external/cert/obligation/rule
18+
* coding-standards/baseline/safety
1819
*/
1920

2021
import cpp

0 commit comments

Comments
 (0)