-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into codeql/upgrade-to-2.16.6
- Loading branch information
Showing
109 changed files
with
2,359 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Applies Coding Standard configuration files in the repository | ||
description: | | ||
Installs Python and indexes the CodeQL Coding Standard configuration files in the repository | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Install Python | ||
id: cs-install-python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.9 | ||
update-environment: false | ||
- name: Install dependencies and process files | ||
shell: bash | ||
run: | | ||
install_dir=$(dirname $(dirname "${{ steps.cs-install-python.outputs.python-path }}")) | ||
if [[ -z "$LD_LIBRARY_PATH" ]]; then | ||
export LD_LIBRARY_PATH="$install_dir/lib" | ||
else | ||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$install_dir/lib" | ||
fi | ||
${{ steps.cs-install-python.outputs.python-path }} -m pip install -r ${GITHUB_ACTION_PATH}/../scripts/configuration/requirements.txt | ||
${{ steps.cs-install-python.outputs.python-path }} ${GITHUB_ACTION_PATH}/../scripts/configuration/process_coding_standards_config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
c/misra/src/rules/RULE-21-24/CallToBannedRandomFunction.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @id c/misra/call-to-banned-random-function | ||
* @name RULE-21-24: The random number generator functions of <stdlib.h> shall not be used | ||
* @description The standard functions rand() and srand() will not give high quality random results | ||
* in all implementations and are therefore banned. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-21-24 | ||
* security | ||
* external/misra/c/2012/amendment3 | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from FunctionCall call, string name | ||
where | ||
not isExcluded(call, Banned2Package::callToBannedRandomFunctionQuery()) and | ||
name = ["rand", "srand"] and | ||
call.getTarget().hasGlobalOrStdName(name) | ||
select call, "Call to banned random number generation function '" + name + "'." |
45 changes: 45 additions & 0 deletions
45
c/misra/src/rules/RULE-7-5/IncorrectlySizedIntegerConstantMacroArgument.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @id c/misra/incorrectly-sized-integer-constant-macro-argument | ||
* @name RULE-7-5: The argument of an integer constant macro shall have an appropriate size | ||
* @description Integer constant macros argument values should be values of a compatible size. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-7-5 | ||
* correctness | ||
* external/misra/c/2012/amendment3 | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.IntegerConstantMacro | ||
import codingstandards.cpp.Literals | ||
|
||
predicate matchesSign(IntegerConstantMacro macro, PossiblyNegativeLiteral literal) { | ||
literal.isNegative() implies macro.isSigned() | ||
} | ||
|
||
predicate matchesSize(IntegerConstantMacro macro, PossiblyNegativeLiteral literal) { | ||
literal.getRawValue() <= macro.maxValue() and | ||
literal.getRawValue() >= macro.minValue() | ||
} | ||
|
||
from | ||
PossiblyNegativeLiteral literal, MacroInvocation invoke, IntegerConstantMacro macro, | ||
string explanation | ||
where | ||
not isExcluded(invoke, Types2Package::incorrectlySizedIntegerConstantMacroArgumentQuery()) and | ||
invoke.getMacro() = macro and | ||
literal = invoke.getExpr() and | ||
( | ||
not matchesSign(macro, literal) and | ||
explanation = " cannot be negative" | ||
or | ||
matchesSign(macro, literal) and | ||
// Wait for BigInt support to check 64 bit macro types. | ||
macro.getSize() < 64 and | ||
not matchesSize(macro, literal) and | ||
explanation = " is outside of the allowed range " + macro.getRangeString() | ||
) | ||
select literal, "Value provided to integer constant macro " + macro.getName() + explanation |
35 changes: 35 additions & 0 deletions
35
c/misra/src/rules/RULE-7-5/IntegerConstantMacroArgumentUsesSuffix.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @id c/misra/integer-constant-macro-argument-uses-suffix | ||
* @name RULE-7-5: The argument of an integer constant macro shall not use literal suffixes u, l, or ul | ||
* @description Integer constant macros should be used integer literal values with no u/l suffix. | ||
* @kind problem | ||
* @precision high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-7-5 | ||
* readability | ||
* maintainability | ||
* external/misra/c/2012/amendment3 | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.IntegerConstantMacro | ||
import codingstandards.cpp.Literals | ||
|
||
string argumentSuffix(MacroInvocation invoke) { | ||
// Extractor strips the suffix unless we look at the unexpanded argument text. | ||
// Unexpanded argument text can be malformed in all sorts of ways, so make | ||
// this match relatively strict, to be safe. | ||
result = invoke.getUnexpandedArgument(0).regexpCapture("([0-9]+|0[xX][0-9A-F]+)([uUlL]+)$", 2) | ||
} | ||
|
||
from MacroInvocation invoke, PossiblyNegativeLiteral argument, string suffix | ||
where | ||
not isExcluded(invoke, Types2Package::integerConstantMacroArgumentUsesSuffixQuery()) and | ||
invoke.getMacro() instanceof IntegerConstantMacro and | ||
invoke.getExpr() = argument and | ||
suffix = argumentSuffix(invoke) | ||
select argument, | ||
"Value suffix '" + suffix + "' is not allowed on provided argument to integer constant macro " + | ||
invoke.getMacroName() + "." |
30 changes: 30 additions & 0 deletions
30
c/misra/src/rules/RULE-7-5/InvalidIntegerConstantMacroArgument.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @id c/misra/invalid-integer-constant-macro-argument | ||
* @name RULE-7-5: The argument of an integer constant macro shall be a literal | ||
* @description Integer constant macros should be given a literal value as an argument. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-7-5 | ||
* correctness | ||
* external/misra/c/2012/amendment3 | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.IntegerConstantMacro | ||
import codingstandards.cpp.Literals | ||
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis | ||
|
||
from MacroInvocation invoke, IntegerConstantMacro macro | ||
where | ||
not isExcluded(invoke, Types2Package::invalidIntegerConstantMacroArgumentQuery()) and | ||
invoke.getMacro() = macro and | ||
( | ||
not invoke.getExpr() instanceof PossiblyNegativeLiteral | ||
or | ||
any(MacroInvocation inner).getParentInvocation() = invoke | ||
) | ||
select invoke.getExpr(), | ||
"Argument to integer constant macro " + macro.getName() + " must be an integer literal." |
Oops, something went wrong.