Skip to content

Commit 480ff55

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/create-github-app-token-2
2 parents 24d7435 + 8d94339 commit 480ff55

File tree

94 files changed

+2516
-489
lines changed

Some content is hidden

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

94 files changed

+2516
-489
lines changed

amendments.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ c,MISRA-C-2012,Amendment4,RULE-8-9,Yes,Clarification,Yes,Import
2424
c,MISRA-C-2012,Amendment4,RULE-9-4,Yes,Clarification,Yes,Import
2525
c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
2626
c,MISRA-C-2012,Amendment4,RULE-18-3,Yes,Clarification,Yes,Import
27-
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,No,Easy
27+
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,Yes,Easy
2828
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
2929
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
3030
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- description: CERT C 2016 (Default)
2+
- qlpack: codeql/cert-c-coding-standards
3+
- include:
4+
kind:
5+
- problem
6+
- path-problem
7+
- external/cert/obligation/rule
8+
- exclude:
9+
tags contain:
10+
- external/cert/default-disabled
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- description: CERT C 2016 (Recommendations)
2+
- qlpack: codeql/cert-c-coding-standards
3+
- include:
4+
kind:
5+
- problem
6+
- path-problem
7+
- external/cert/obligation/recommendation
8+
- exclude:
9+
tags contain:
10+
- external/cert/default-disabled
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
- description: CERT C 2016 (Default)
2-
- qlpack: codeql/cert-c-coding-standards
3-
- include:
4-
kind:
5-
- problem
6-
- path-problem
7-
- exclude:
8-
tags contain:
9-
- external/cert/default-disabled
1+
- description: "DEPRECATED - CERT C 2016 - use cert-c-default.qls instead"
2+
- import: codeql-suites/cert-c-default.qls

c/cert/src/qlpack.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.44.0-dev
2+
version: 2.45.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT
6+
default-suite-file: codeql-suites/cert-c-default.qls
67
dependencies:
78
codeql/common-c-coding-standards: '*'
89
codeql/cpp-all: 2.1.1

c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import codingstandards.c.cert
1919
import codingstandards.cpp.types.Compatible
2020
import ExternalIdentifiers
2121

22+
predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
23+
not f1 = f2 and
24+
f1.getDeclaration() = f2.getDeclaration() and
25+
f1.getName() = f2.getName()
26+
}
27+
2228
from ExternalIdentifiers d, FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
2329
where
2430
not isExcluded(f1, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
@@ -29,10 +35,12 @@ where
2935
f1.getName() = f2.getName() and
3036
(
3137
//return type check
32-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig>::equalReturnTypes(f1, f2)
38+
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalReturnTypes(f1,
39+
f2)
3340
or
3441
//parameter type check
35-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig>::equalParameterTypes(f1, f2)
42+
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalParameterTypes(f1,
43+
f2)
3644
) and
3745
// Apply ordering on start line, trying to avoid the optimiser applying this join too early
3846
// in the pipeline

c/cert/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.44.0-dev
2+
version: 2.45.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/codingstandards/c/TgMath.qll

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
import cpp
22

3-
private string getATgMathMacroName(boolean allowComplex) {
3+
private string getATgMathMacroName(boolean allowComplex, int numberOfParameters) {
44
allowComplex = true and
5+
numberOfParameters = 1 and
56
result =
67
[
78
"acos", "acosh", "asin", "asinh", "atan", "atanh", "carg", "cimag", "conj", "cos", "cosh",
8-
"cproj", "creal", "exp", "fabs", "log", "pow", "sin", "sinh", "sqrt", "tan", "tanh"
9+
"cproj", "creal", "exp", "fabs", "log", "sin", "sinh", "sqrt", "tan", "tanh"
10+
]
11+
or
12+
allowComplex = true and
13+
numberOfParameters = 2 and
14+
result = "pow"
15+
or
16+
allowComplex = false and
17+
numberOfParameters = 1 and
18+
result =
19+
[
20+
"cbrt", "ceil", "erf", "erfc", "exp2", "expm1", "floor", "ilogb", "lgamma", "llrint",
21+
"llround", "log10", "log1p", "log2", "logb", "lrint", "lround", "nearbyint", "rint", "round",
22+
"tgamma", "trunc",
923
]
1024
or
1125
allowComplex = false and
26+
numberOfParameters = 2 and
1227
result =
1328
[
14-
"atan2", "cbrt", "ceil", "copysign", "erf", "erfc", "exp2", "expm1", "fdim", "floor", "fma",
15-
"fmax", "fmin", "fmod", "frexp", "hypot", "ilogb", "ldexp", "lgamma", "llrint", "llround",
16-
"log10", "log1p", "log2", "logb", "lrint", "lround", "nearbyint", "nextafter", "nexttoward",
17-
"remainder", "remquo", "rint", "round", "scalbn", "scalbln", "tgamma", "trunc",
29+
"atan2", "copysign", "fdim", "fmax", "fmin", "fmod", "frexp", "hypot", "ldexp", "nextafter",
30+
"nexttoward", "remainder", "scalbn", "scalbln"
1831
]
32+
or
33+
allowComplex = false and
34+
numberOfParameters = 3 and
35+
result = ["fma", "remquo"]
1936
}
2037

2138
private predicate hasOutputArgument(string macroName, int index) {
@@ -27,19 +44,41 @@ private predicate hasOutputArgument(string macroName, int index) {
2744
class TgMathInvocation extends MacroInvocation {
2845
Call call;
2946
boolean allowComplex;
47+
int numberOfParameters;
3048

3149
TgMathInvocation() {
32-
this.getMacro().getName() = getATgMathMacroName(allowComplex) and
50+
this.getMacro().getName() = getATgMathMacroName(allowComplex, numberOfParameters) and
3351
call = getBestCallInExpansion(this)
3452
}
3553

54+
/** Account for extra parameters added by gcc */
55+
private int getParameterOffset() {
56+
// Gcc calls look something like: `__builtin_tgmath(cosf, cosd, cosl, arg)`, in this example
57+
// there is a parameter offset of 3, so `getOperandArgument(0)` is equivalent to
58+
// `call.getArgument(3)`.
59+
result = call.getNumberOfArguments() - numberOfParameters
60+
}
61+
3662
Expr getOperandArgument(int i) {
37-
result = call.getArgument(i) and
38-
not hasOutputArgument(call.getTarget().getName(), i)
63+
i >= 0 and
64+
result = call.getArgument(i + getParameterOffset()) and
65+
//i in [0..numberOfParameters - 1] and
66+
not hasOutputArgument(getMacro().getName(), i)
67+
}
68+
69+
/** Get all explicit conversions, except those added by clang in the macro body */
70+
Expr getExplicitlyConvertedOperandArgument(int i) {
71+
exists(Expr explicitConv |
72+
explicitConv = getOperandArgument(i).getExplicitlyConverted() and
73+
// clang explicitly casts most arguments, but not some integer arguments such as in `scalbn`.
74+
if call.getTarget().getName().matches("__tg_%") and explicitConv instanceof Conversion
75+
then result = explicitConv.(Conversion).getExpr()
76+
else result = explicitConv
77+
)
3978
}
4079

4180
int getNumberOfOperandArguments() {
42-
result = call.getNumberOfArguments() - count(int i | hasOutputArgument(getMacroName(), i))
81+
result = numberOfParameters - count(int i | hasOutputArgument(getMacroName(), i))
4382
}
4483

4584
Expr getAnOperandArgument() { result = getOperandArgument(_) }

c/common/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.44.0-dev
2+
version: 2.45.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.44.0-dev
2+
version: 2.45.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

0 commit comments

Comments
 (0)