Skip to content

Commit 7205b5e

Browse files
committed
Release v2.1.0
1 parent ae69327 commit 7205b5e

File tree

330 files changed

+14322
-32140
lines changed

Some content is hidden

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

330 files changed

+14322
-32140
lines changed

.github/actions/install-codeql/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ runs:
9090
9191
if [ "$CODEQL_STDLIB_VERSION" != "latest" ]
9292
then
93-
push codeql-stdlib
93+
pushd codeql-stdlib
9494
echo "::debug::Switching to revision $CODEQL_STDLIB_VERSION"
9595
git checkout $CODEQL_STDLIB_VERSION
9696
popd

.github/workflows/code-scanning-pack-gen.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ on:
55
branches:
66
- main
77
- "rc/**"
8+
- "c-coding-standards"
89

910
push:
1011
branches:
1112
- main
1213
- "rc/**"
14+
- "c-coding-standards"
1315

1416
env:
1517
XARGS_MAX_PROCS: 4

.vscode/tasks.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
},
1313
"problemMatcher": []
1414
},
15+
16+
{
17+
"label": "🔃 Standards Automation: Switch To Test or Implementation",
18+
"type": "shell",
19+
"command": "pwsh .${pathSeparator}scripts${pathSeparator}vscode${pathSeparator}Get-TestOrQueryDirectoryForCurrentFile.ps1 -CurrentFile ${file}",
20+
"presentation": {
21+
"reveal": "never",
22+
"panel": "dedicated"
23+
},
24+
"problemMatcher": []
25+
},
26+
1527
{
1628
"label": "Standards Automation: Install Deps",
1729
"type": "shell",
@@ -157,6 +169,7 @@
157169
"BannedTypes",
158170
"BannedFunctions",
159171
"Classes",
172+
"Comments",
160173
"Concurrency",
161174
"Const",
162175
"Declarations",
@@ -171,14 +184,13 @@
171184
"Macros",
172185
"Naming",
173186
"Scope",
174-
"Side-effects1",
175-
"Side-effects2",
176187
"Classes",
177188
"SmartPointers1",
178189
"SmartPointers2",
179190
"SideEffects1",
180191
"SideEffects2",
181192
"Strings",
193+
"Syntax",
182194
"Templates",
183195
"Classes",
184196
"Freed",

c/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: cert-c-coding-standards
2-
version: 2.0.0
2+
version: 2.1.0
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<fragment>
6+
<p>None</p>
7+
</fragment>
8+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
2+
<qhelp>
3+
<section title="Classification">
4+
<ul>
5+
<li>required</li>
6+
<li>implementation</li>
7+
<li>automated</li>
8+
</ul>
9+
</section>
10+
11+
<section title="Rationale">
12+
<p>
13+
...
14+
</p>
15+
16+
</section>
17+
18+
<section title="Exception">
19+
<p>
20+
...
21+
</p>
22+
</section>
23+
24+
<example>
25+
<sample src="standard-example.c"></sample>
26+
</example>
27+
28+
<section title="See more">
29+
<ul>
30+
<li>...</li>
31+
</ul>
32+
</section>
33+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
<!-- THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. -->
4+
<overview>
5+
<p>This query implements the CERT-C rule EXP30-C:</p>
6+
<blockquote>
7+
<p>Do not depend on the order of evaluation for side effects</p>
8+
</blockquote>
9+
</overview>
10+
<include src="DependenceOnOrderOfFunctionArgumentsForSideEffects-standard.qhelp" />
11+
<section title="Implementation notes">
12+
<include src="DependenceOnOrderOfFunctionArgumentsForSideEffects-implementation.qhelp" />
13+
</section>
14+
<references>
15+
<li>
16+
CERT-C:
17+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">EXP30-C: Do not depend on the order of evaluation for side effects</a>
18+
.
19+
</li>
20+
</references>
21+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @id c/cert/dependence-on-order-of-function-arguments-for-side-effects
3+
* @name EXP30-C: Do not depend on the order of evaluation of function call arguments for side effects
4+
* @description Depending on the order of evaluation for side effects in function call arguments can
5+
* result in unexpected program behavior.
6+
* @kind problem
7+
* @precision high
8+
* @problem.severity warning
9+
* @tags external/cert/id/exp30-c
10+
* correctness
11+
* external/cert/obligation/rule
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.cert
16+
import codingstandards.cpp.SideEffect
17+
import semmle.code.cpp.dataflow.DataFlow
18+
import semmle.code.cpp.dataflow.TaintTracking
19+
import semmle.code.cpp.valuenumbering.GlobalValueNumberingImpl
20+
21+
/** Holds if the function's return value is derived from the `AliasParamter` p. */
22+
predicate returnValueDependsOnAliasParameter(AliasParameter p) {
23+
exists(ReturnStmt ret | ret = p.getFunction().getBlock().getAStmt() |
24+
TaintTracking::localTaint(DataFlow::parameterNode(p), DataFlow::exprNode(ret.getExpr()))
25+
or
26+
exists(FieldAccess fa, VariableAccess va | fa.getQualifier() = va and va.getTarget() = p |
27+
TaintTracking::localTaint(DataFlow::exprNode(fa), DataFlow::exprNode(ret.getExpr()))
28+
)
29+
or
30+
exists(FunctionCall call, VariableAccess va | call.getQualifier() = va and va.getTarget() = p |
31+
TaintTracking::localTaint(DataFlow::exprNode(call), DataFlow::exprNode(ret.getExpr()))
32+
)
33+
or
34+
exists(VariableAccess va | va.getTarget() = p | ret.getAChild+() = va)
35+
)
36+
or
37+
exists(FunctionCall call, ReturnStmt ret, int i, AliasParameter q |
38+
ret = p.getFunction().getBlock().getAStmt() and call.getEnclosingFunction() = p.getFunction()
39+
|
40+
DataFlow::localFlow(DataFlow::parameterNode(p), DataFlow::exprNode(call.getArgument(i))) and
41+
q = call.getTarget().getParameter(i) and
42+
returnValueDependsOnAliasParameter(q) and
43+
TaintTracking::localTaint(DataFlow::exprNode(call), DataFlow::exprNode(ret.getExpr()))
44+
)
45+
}
46+
47+
/** Holds if the function `f`'s return value is derived from the global variable `v`. */
48+
predicate returnValueDependsOnGlobalVariable(Function f, GlobalVariable v) {
49+
exists(ReturnStmt ret, VariableAccess va |
50+
ret = f.getBlock().getAStmt() and va.getTarget() = v and va.getEnclosingFunction() = f
51+
|
52+
TaintTracking::localTaint(DataFlow::exprNode(va), DataFlow::exprNode(ret.getExpr()))
53+
)
54+
or
55+
exists(ReturnStmt ret, FunctionCall call |
56+
ret = f.getBlock().getAStmt() and
57+
call.getEnclosingFunction() = f and
58+
returnValueDependsOnGlobalVariable(call.getTarget(), v) and
59+
TaintTracking::localTaint(DataFlow::exprNode(call), DataFlow::exprNode(ret.getExpr()))
60+
)
61+
}
62+
63+
/** Holds if the member function `f`'s return value is derived from the member variable `v`. */
64+
predicate returnValueDependsOnMemberVariable(MemberFunction f, MemberVariable v) {
65+
exists(ReturnStmt ret, VariableAccess va |
66+
ret = f.getBlock().getAStmt() and
67+
va.getTarget() = v and
68+
va.getEnclosingFunction() = f and
69+
v.getDeclaringType() = f.getDeclaringType()
70+
|
71+
TaintTracking::localTaint(DataFlow::exprNode(va), DataFlow::exprNode(ret.getExpr()))
72+
)
73+
}
74+
75+
from
76+
FunctionCall call, Function f1, Function f2, int i, int j, FunctionCall arg1, FunctionCall arg2,
77+
Variable v1, Variable v2
78+
where
79+
not isExcluded(call,
80+
SideEffects1Package::dependenceOnOrderOfFunctionArgumentsForSideEffectsQuery()) and
81+
arg1 = call.getArgument(i) and
82+
arg2 = call.getArgument(j) and
83+
i < j and
84+
arg1.getTarget() = f1 and
85+
arg2.getTarget() = f2 and
86+
(
87+
// Considering the shared states:
88+
// - pointer or reference arguments being used in both functions
89+
exists(AliasParameter p1, AliasParameter p2 |
90+
v1 = p1 and
91+
v2 = p2 and
92+
f1.getAParameter() = p1 and
93+
f2.getAParameter() = p2 and
94+
p1.isModified() and
95+
p2.isModified() and
96+
globalValueNumber(arg1.getArgument(p1.getIndex())) =
97+
globalValueNumber(arg2.getArgument(p2.getIndex())) and
98+
returnValueDependsOnAliasParameter(p1) and
99+
returnValueDependsOnAliasParameter(p2)
100+
)
101+
or
102+
// - global variables being used in both functions
103+
exists(GlobalVariable v, VariableEffect ve1, VariableEffect ve2 |
104+
v1 = v and
105+
v2 = v and
106+
returnValueDependsOnGlobalVariable(f1, v) and
107+
returnValueDependsOnGlobalVariable(f2, v) and
108+
ve1.getTarget() = v and
109+
ve2.getTarget() = v
110+
)
111+
or
112+
// - member variables that can be modified in both functions
113+
exists(MemberVariable v |
114+
v1 = v and
115+
v2 = v and
116+
returnValueDependsOnMemberVariable(f1, v) and
117+
returnValueDependsOnMemberVariable(f2, v) and
118+
v = getAMemberVariableEffect(f1).getTarget() and
119+
v = getAMemberVariableEffect(f2).getTarget() and
120+
(
121+
globalValueNumber(arg1.getQualifier()) = globalValueNumber(arg2.getQualifier())
122+
or
123+
v.isStatic() and arg1.getQualifier().getType() = arg2.getQualifier().getType()
124+
)
125+
)
126+
)
127+
select call,
128+
"Depending on the order of evaluation for the arguments $@ and $@ for side effects on shared state is unspecified and can result in unexpected behavior.",
129+
arg1, arg1.toString(), arg2, arg2.toString()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<fragment>
6+
<p>None</p>
7+
</fragment>
8+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
2+
<qhelp>
3+
<section title="Classification">
4+
<ul>
5+
<li>required</li>
6+
<li>implementation</li>
7+
<li>automated</li>
8+
</ul>
9+
</section>
10+
11+
<section title="Rationale">
12+
<p>
13+
...
14+
</p>
15+
16+
</section>
17+
18+
<section title="Exception">
19+
<p>
20+
...
21+
</p>
22+
</section>
23+
24+
<example>
25+
<sample src="standard-example.c"></sample>
26+
</example>
27+
28+
<section title="See more">
29+
<ul>
30+
<li>...</li>
31+
</ul>
32+
</section>
33+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
<!-- THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. -->
4+
<overview>
5+
<p>This query implements the CERT-C rule EXP30-C:</p>
6+
<blockquote>
7+
<p>Do not depend on the order of evaluation for side effects</p>
8+
</blockquote>
9+
</overview>
10+
<include src="DependenceOnOrderOfScalarEvaluationForSideEffects-standard.qhelp" />
11+
<section title="Implementation notes">
12+
<include src="DependenceOnOrderOfScalarEvaluationForSideEffects-implementation.qhelp" />
13+
</section>
14+
<references>
15+
<li>
16+
CERT-C:
17+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">EXP30-C: Do not depend on the order of evaluation for side effects</a>
18+
.
19+
</li>
20+
</references>
21+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @id c/cert/dependence-on-order-of-scalar-evaluation-for-side-effects
3+
* @name EXP30-C: Do not depend on the order of scalar object evaluation for side effects
4+
* @description Depending on the order of evaluation for side effects for evaluation of scalar
5+
* objects that are unsequenced results in undefined behavior.
6+
* @kind problem
7+
* @precision high
8+
* @problem.severity warning
9+
* @tags external/cert/id/exp30-c
10+
* correctness
11+
* external/cert/obligation/rule
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.cert
16+
import codingstandards.cpp.SideEffect
17+
import codingstandards.c.Ordering
18+
import codingstandards.c.orderofevaluation.VariableAccessOrdering
19+
20+
from
21+
VariableAccessInFullExpressionOrdering config, FullExpr e, ScalarVariable v, VariableEffect ve,
22+
VariableAccess va1, VariableAccess va2
23+
where
24+
not isExcluded(e, SideEffects1Package::dependenceOnOrderOfScalarEvaluationForSideEffectsQuery()) and
25+
e = va1.(ConstituentExpr).getFullExpr() and
26+
va1 = ve.getAnAccess() and
27+
config.isUnsequenced(va1, va2) and
28+
v = va1.getTarget()
29+
select e, "Scalar object referenced by $@ has a $@ that is unsequenced in relative to another $@.",
30+
v, v.getName(), ve, "side-effect", va2, "side-effect or value computation"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<fragment>
6+
<p>None</p>
7+
</fragment>
8+
</qhelp>

0 commit comments

Comments
 (0)