Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 480ff55

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

File tree

94 files changed

+2516
-489
lines changed
Filter options

Some content is hidden

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

94 files changed

+2516
-489
lines changed

‎amendments.csv

Copy file name to clipboardExpand all lines: amendments.csv
+1-1Lines 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
+10Lines 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
+10Lines 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
+2-9Lines 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

Copy file name to clipboard
+2-1Lines 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

Copy file name to clipboardExpand all lines: c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql
+10-2Lines 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

Copy file name to clipboardExpand all lines: c/cert/test/qlpack.yml
+1-1Lines 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

Copy file name to clipboardExpand all lines: c/common/src/codingstandards/c/TgMath.qll
+49-10Lines 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

Copy file name to clipboardExpand all lines: c/common/src/qlpack.yml
+1-1Lines 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

Copy file name to clipboardExpand all lines: c/common/test/qlpack.yml
+1-1Lines 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:

‎c/common/test/rules/functionnoreturnattributecondition/test.c

Copy file name to clipboardExpand all lines: c/common/test/rules/functionnoreturnattributecondition/test.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ _Noreturn void test_noreturn_f10(int i) { // COMPLIANT
7777
case 4:
7878
thrd_exit(0);
7979
break;
80-
default:
80+
default:;
8181
jmp_buf jb;
8282
longjmp(jb, 0);
8383
}

‎c/misra/src/qlpack.yml

Copy file name to clipboardExpand all lines: c/misra/src/qlpack.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.44.0-dev
2+
version: 2.45.0-dev
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

‎c/misra/src/rules/RULE-13-2/UnsequencedAtomicReads.ql

Copy file name to clipboardExpand all lines: c/misra/src/rules/RULE-13-2/UnsequencedAtomicReads.ql
+38-12Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ import semmle.code.cpp.dataflow.TaintTracking
1717
import codingstandards.c.misra
1818
import codingstandards.c.Ordering
1919
import codingstandards.c.orderofevaluation.VariableAccessOrdering
20+
import codingstandards.cpp.StdFunctionOrMacro
2021

2122
class AtomicAccessInFullExpressionOrdering extends Ordering::Configuration {
2223
AtomicAccessInFullExpressionOrdering() { this = "AtomicAccessInFullExpressionOrdering" }
2324

2425
override predicate isCandidate(Expr e1, Expr e2) {
2526
exists(AtomicVariableAccess a, AtomicVariableAccess b, FullExpr e | a = e1 and b = e2 |
2627
a.getTarget() = b.getTarget() and
27-
a.(ConstituentExpr).getFullExpr() = e and
28-
b.(ConstituentExpr).getFullExpr() = e and
28+
a.getARead().(ConstituentExpr).getFullExpr() = e and
29+
b.getARead().(ConstituentExpr).getFullExpr() = e and
2930
not a = b
3031
)
3132
}
@@ -39,21 +40,40 @@ class AtomicAccessInFullExpressionOrdering extends Ordering::Configuration {
3940
class AtomicVariableAccess extends VariableAccess {
4041
AtomicVariableAccess() { getTarget().getType().hasSpecifier("atomic") }
4142

42-
/* Get the `atomic_<read|write>()` call this VarAccess occurs in. */
43-
FunctionCall getAtomicFunctionCall() {
44-
exists(AddressOfExpr addrParent, FunctionCall fc |
45-
fc.getTarget().getName().matches("__c11_atomic%") and
43+
/* Get the `atomic_load()` call this VarAccess occurs in. */
44+
Expr getAtomicFunctionRead() {
45+
exists(AddressOfExpr addrParent, AtomicReadOrWriteCall fc |
46+
fc.getName().matches("atomic_load%") and
47+
// StdFunctionOrMacro arguments are not necessarily reliable, so we look for any AddressOfExpr
48+
// that is an argument to a call to `atomic_load`.
4649
addrParent = fc.getArgument(0) and
4750
addrParent.getAnOperand() = this and
48-
result = fc
51+
result = fc.getExpr()
52+
)
53+
}
54+
55+
/* Get the `atomic_store()` call this VarAccess occurs in. */
56+
Expr getAtomicFunctionWrite(Expr storedValue) {
57+
exists(AddressOfExpr addrParent, AtomicReadOrWriteCall fc |
58+
addrParent = fc.getArgument(0) and
59+
addrParent.getAnOperand() = this and
60+
result = fc.getExpr() and
61+
(
62+
fc.getName().matches(["%store%", "%exchange%", "%fetch_%"]) and
63+
not fc.getName().matches("%compare%") and
64+
storedValue = fc.getArgument(1)
65+
or
66+
fc.getName().matches(["%compare%"]) and
67+
storedValue = fc.getArgument(2)
68+
)
4969
)
5070
}
5171

5272
/**
5373
* Gets an assigned expr, either in the form `x = <result>` or `atomic_store(&x, <result>)`.
5474
*/
5575
Expr getAnAssignedExpr() {
56-
result = getAtomicFunctionCall().getArgument(1)
76+
exists(getAtomicFunctionWrite(result))
5777
or
5878
exists(AssignExpr assign |
5979
assign.getLValue() = this and
@@ -65,19 +85,25 @@ class AtomicVariableAccess extends VariableAccess {
6585
* Gets the expression holding this variable access, either in the form `x` or `atomic_read(&x)`.
6686
*/
6787
Expr getARead() {
68-
result = getAtomicFunctionCall()
88+
result = getAtomicFunctionRead()
6989
or
7090
result = this
7191
}
7292
}
7393

7494
from
7595
AtomicAccessInFullExpressionOrdering config, FullExpr e, Variable v, AtomicVariableAccess va1,
76-
AtomicVariableAccess va2
96+
AtomicVariableAccess va2, Expr va1Read, Expr va2Read
7797
where
7898
not isExcluded(e, SideEffects3Package::unsequencedAtomicReadsQuery()) and
79-
e = va1.(ConstituentExpr).getFullExpr() and
80-
config.isUnsequenced(va1, va2) and
99+
va1Read = va1.getARead() and
100+
va2Read = va2.getARead() and
101+
e = va1Read.(ConstituentExpr).getFullExpr() and
102+
// Careful here. The `VariableAccess` in a pair of atomic function calls may not be unsequenced,
103+
// for instance in gcc where atomic functions expand to StmtExprs, which have clear sequences.
104+
// In this case, the result of `getARead()` for a pair of atomic function calls may be
105+
// unsequenced even though the `VariableAccess`es within those calls are not.
106+
config.isUnsequenced(va1Read, va2Read) and
81107
v = va1.getTarget() and
82108
v = va2.getTarget() and
83109
// Exclude cases where the variable is assigned a value tainted by the other variable access.

‎c/misra/src/rules/RULE-21-22/TgMathArgumentWithInvalidEssentialType.ql

Copy file name to clipboardExpand all lines: c/misra/src/rules/RULE-21-22/TgMathArgumentWithInvalidEssentialType.ql
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ string getAllowedTypesString(TgMathInvocation call) {
3434
else result = "essentially signed, unsigned, or real floating type"
3535
}
3636

37-
from TgMathInvocation call, Expr arg, int argIndex, Type type, EssentialTypeCategory category
37+
from
38+
TgMathInvocation call, Expr convertedArg, Expr unconverted, int argIndex, Type type,
39+
EssentialTypeCategory category
3840
where
3941
not isExcluded(call, EssentialTypes2Package::tgMathArgumentWithInvalidEssentialTypeQuery()) and
40-
arg = call.getOperandArgument(argIndex) and
41-
type = getEssentialType(arg) and
42+
// We must handle conversions specially, as clang inserts casts in the macro body we want to ignore.
43+
convertedArg = call.getExplicitlyConvertedOperandArgument(argIndex) and
44+
unconverted = convertedArg.getUnconverted() and
45+
// Do not use `convertedArg.getEssentialType()`, as that is affected by clang's casts in the macro body.
46+
type = getEssentialTypeBeforeConversions(convertedArg) and
4247
category = getEssentialTypeCategory(type) and
4348
not category = getAnAllowedEssentialTypeCategory(call)
44-
select arg,
49+
select unconverted,
4550
"Argument " + (argIndex + 1) + " provided to type-generic macro '" + call.getMacroName() +
4651
"' has " + category.toString().toLowerCase() + ", which is not " + getAllowedTypesString(call) +
4752
"."

‎c/misra/src/rules/RULE-21-23/TgMathArgumentsWithDifferingStandardType.ql

Copy file name to clipboardExpand all lines: c/misra/src/rules/RULE-21-23/TgMathArgumentsWithDifferingStandardType.ql
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ Type canonicalize(Type type) {
5858
else result = type
5959
}
6060

61-
Type getEffectiveStandardType(Expr e) {
62-
result = canonicalize(getPromotedType(e.getExplicitlyConverted()))
63-
}
61+
Type getEffectiveStandardType(Expr e) { result = canonicalize(getPromotedType(e)) }
6462

6563
from TgMathInvocation call, Type firstType
6664
where
6765
not isExcluded(call, EssentialTypes2Package::tgMathArgumentsWithDifferingStandardTypeQuery()) and
68-
firstType = getEffectiveStandardType(call.getAnOperandArgument()) and
69-
not forall(Expr arg | arg = call.getAnOperandArgument() |
66+
firstType = getEffectiveStandardType(call.getExplicitlyConvertedOperandArgument(0)) and
67+
not forall(Expr arg | arg = call.getExplicitlyConvertedOperandArgument(_) |
7068
firstType = getEffectiveStandardType(arg)
7169
)
7270
select call,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.