Skip to content

Commit e78f15b

Browse files
committed
Release v2.5.0
1 parent c921864 commit e78f15b

File tree

228 files changed

+3933
-768
lines changed

Some content is hidden

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

228 files changed

+3933
-768
lines changed

.vscode/tasks.json

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
"Classes",
172172
"Comments",
173173
"Concurrency",
174+
"Concurrency",
175+
"Concurrency1",
176+
"Concurrency2",
177+
"Concurrency3",
174178
"Conditionals",
175179
"Const",
176180
"DeadCode",
@@ -199,6 +203,8 @@
199203
"OperatorInvariants",
200204
"Operators",
201205
"Pointers",
206+
"Pointers1",
207+
"Pointers2",
202208
"Scope",
203209
"SideEffects1",
204210
"SideEffects2",

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.4.0
2+
version: 2.5.0
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards
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,18 @@
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 CON32-C:</p>
6+
<blockquote>
7+
<p>Prevent data races when accessing bit-fields from multiple threads</p>
8+
</blockquote>
9+
</overview>
10+
<include src="PreventDataRacesWithMultipleThreads-standard.qhelp" />
11+
<references>
12+
<li>
13+
CERT-C:
14+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">CON32-C: Prevent data races when accessing bit-fields from multiple threads</a>
15+
.
16+
</li>
17+
</references>
18+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id c/cert/prevent-data-races-with-multiple-threads
3+
* @name CON32-C: Prevent data races when accessing bit-fields from multiple threads
4+
* @description Accesses to bit fields without proper concurrency protection can result in data
5+
* races.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/cert/id/con32-c
10+
* correctness
11+
* concurrency
12+
* external/cert/obligation/rule
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.cert
17+
import codingstandards.cpp.rules.guardaccesstobitfields.GuardAccessToBitFields
18+
19+
class PreventDataRacesWithMultipleThreadsQuery extends GuardAccessToBitFieldsSharedQuery {
20+
PreventDataRacesWithMultipleThreadsQuery() {
21+
this = Concurrency1Package::preventDataRacesWithMultipleThreadsQuery()
22+
}
23+
}

c/cert/src/rules/CON32-C/standard-example.c

Whitespace-only changes.
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,18 @@
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 CON33-C:</p>
6+
<blockquote>
7+
<p>Avoid race conditions when using library functions</p>
8+
</blockquote>
9+
</overview>
10+
<include src="RaceConditionsWhenUsingLibraryFunctions-standard.qhelp" />
11+
<references>
12+
<li>
13+
CERT-C:
14+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">CON33-C: Avoid race conditions when using library functions</a>
15+
.
16+
</li>
17+
</references>
18+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @id c/cert/race-conditions-when-using-library-functions
3+
* @name CON33-C: Avoid race conditions when using library functions
4+
* @description Certain functions may cause race conditions when used from a threaded context.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/con33-c
9+
* correctness
10+
* concurrency
11+
* external/cert/obligation/rule
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.cert
16+
import codingstandards.cpp.Concurrency
17+
18+
from ThreadedCFN node
19+
where
20+
not isExcluded(node, Concurrency1Package::raceConditionsWhenUsingLibraryFunctionsQuery()) and
21+
node.(FunctionCall).getTarget().getName() =
22+
[
23+
"rand", "srand", "getenv", "strtok", "strerror", "asctime", "ctime", "localtime", "gmtime",
24+
"setlocale", "atomic_init", "ATOMIC_VAR_INIT", "tmpnam", "mbrtoc16", "c16rtomb", "mbrtoc32",
25+
"c32rtomb"
26+
]
27+
select node,
28+
"Concurrent call to non-reeantrant function $@.", node.(FunctionCall).getTarget(), node.(FunctionCall).getTarget().getName()

c/cert/src/rules/CON33-C/standard-example.c

Whitespace-only changes.
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 CON37-C:</p>
6+
<blockquote>
7+
<p>Do not call signal() in a multithreaded program</p>
8+
</blockquote>
9+
</overview>
10+
<include src="DoNotCallSignalInMultithreadedProgram-standard.qhelp" />
11+
<section title="Implementation scope">
12+
<p></p>
13+
</section>
14+
<references>
15+
<li>
16+
CERT-C:
17+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">CON37-C: Do not call signal() in a multithreaded program</a>
18+
.
19+
</li>
20+
</references>
21+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @id c/cert/do-not-call-signal-in-multithreaded-program
3+
* @name CON37-C: Do not call signal() in a multithreaded program
4+
* @description Calling signal() from within a multithreaded program can result in unpredictable
5+
* program behavior.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/cert/id/con37-c
10+
* correctness
11+
* concurrency
12+
* external/cert/obligation/rule
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.cert
17+
import codingstandards.cpp.Concurrency
18+
19+
from FunctionCall fc
20+
// This should only be applied in the context of a multi-threaded program (since
21+
// it is valid to be used in a non-threaded program) so we filter those types of
22+
// programs out here
23+
where
24+
not isExcluded(fc, Concurrency1Package::doNotCallSignalInMultithreadedProgramQuery()) and
25+
fc.getTarget().getName() = "signal" and
26+
exists(ThreadedFunction f)
27+
select fc,
28+
"Call to `signal()` in multithreaded programs."

c/cert/src/rules/CON37-C/standard-example.c

Whitespace-only changes.
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,18 @@
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 STR34-C:</p>
6+
<blockquote>
7+
<p>Cast characters to unsigned char before converting to larger integer sizes</p>
8+
</blockquote>
9+
</overview>
10+
<include src="CastCharBeforeConvertingToLargerSizes-standard.qhelp" />
11+
<references>
12+
<li>
13+
CERT-C:
14+
<a href="https://wiki.sei.cmu.edu/confluence/display/c">STR34-C: Cast characters to unsigned char before converting to larger integer sizes</a>
15+
.
16+
</li>
17+
</references>
18+
</qhelp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @id c/cert/cast-char-before-converting-to-larger-sizes
3+
* @name STR34-C: Cast characters to unsigned char before converting to larger integer sizes
4+
* @description Not casting smaller char sizes to unsigned char before converting to lager integer
5+
* sizes may lead to unpredictable program behavior.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/cert/id/str34-c
10+
* correctness
11+
* security
12+
* external/cert/obligation/rule
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.cert
17+
import semmle.code.cpp.commons.CommonType
18+
19+
from Cast c
20+
where
21+
not isExcluded(c, Strings3Package::castCharBeforeConvertingToLargerSizesQuery()) and
22+
// find cases where there is a conversion happening wherein the
23+
// base type is a char
24+
c.getExpr().getType() instanceof CharType and
25+
not c.getExpr().getType() instanceof UnsignedCharType and
26+
// it's a bigger type
27+
c.getType().getSize() > c.getExpr().getType().getSize() and
28+
// and it's some kind of integer type
29+
c.getType() instanceof IntegralType
30+
select c.getExpr(),
31+
"Expression not converted to `unsigned char` before converting to a larger integer type."

c/cert/src/rules/STR34-C/standard-example.c

Whitespace-only changes.
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>

0 commit comments

Comments
 (0)