Skip to content

Commit 1e63711

Browse files
authored
Merge branch 'main' into knewbury01/Declarations4
2 parents 2224ab5 + be885f4 commit 1e63711

File tree

162 files changed

+4537
-272
lines changed

Some content is hidden

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

162 files changed

+4537
-272
lines changed

.github/workflows/bump-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111

1212
apply-version-bump:
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-22.04
1414
name: Apply Version Bump
1515
steps:
1616
- name: Checkout

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919
jobs:
2020
prepare-code-scanning-pack-matrix:
2121
name: Prepare CodeQL Code Scanning pack matrix
22-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-22.04
2323
outputs:
2424
matrix: ${{ steps.export-code-scanning-pack-matrix.outputs.matrix }}
2525
steps:

.github/workflows/codeql_unit_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
jobs:
1515
prepare-unit-test-matrix:
1616
name: Prepare CodeQL unit test matrix
17-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-22.04
1818
outputs:
1919
matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }}
2020
steps:
@@ -157,7 +157,7 @@ jobs:
157157
validate-test-results:
158158
name: Validate test results
159159
needs: [run-test-suites]
160-
runs-on: ubuntu-latest
160+
runs-on: ubuntu-22.04
161161
steps:
162162
- name: Collect test results
163163
uses: actions/download-artifact@v2

.github/workflows/create-draft-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
jobs:
2222
create-draft-release:
2323
name: Create draft release
24-
runs-on: ubuntu-latest
24+
runs-on: ubuntu-22.04
2525
env:
2626
# AWS CONFIGURATION
2727
AWS_EC2_INSTANCE_TYPE: ${{ github.event.inputs.aws_ec2_instance_type }}

.github/workflows/generate-html-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
generate-html-doc:
1717
name: Generate HTML documentation
18-
runs-on: ubuntu-latest
18+
runs-on: ubuntu-22.04
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v2

.github/workflows/standard_library_upgrade_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
jobs:
1515
prepare-unit-test-matrix:
1616
name: Prepare CodeQL unit test matrix
17-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-22.04
1818
outputs:
1919
matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }}
2020
steps:
@@ -154,7 +154,7 @@ jobs:
154154
validate-test-results:
155155
name: Validate test results
156156
needs: [run-test-suites]
157-
runs-on: ubuntu-latest
157+
runs-on: ubuntu-22.04
158158
steps:
159159
- name: Install Python
160160
uses: actions/setup-python@v4

.github/workflows/upgrade_codeql_dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
env:
2121
CODEQL_CLI_VERSION: ${{ github.event.inputs.codeql_cli_version }}
2222
CODEQL_LIB_COMMIT: ${{ github.event.inputs.codeql_standard_library_commit }}
23-
runs-on: ubuntu-latest
23+
runs-on: ubuntu-22.04
2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@v2

.github/workflows/validate-coding-standards.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
jobs:
1919
validate-package-files:
2020
name: Validate Package Files
21-
runs-on: ubuntu-latest
21+
runs-on: ubuntu-22.04
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v2
@@ -63,7 +63,7 @@ jobs:
6363
6464
validate-codeql-format:
6565
name: "Validate CodeQL Format"
66-
runs-on: ubuntu-latest
66+
runs-on: ubuntu-22.04
6767
steps:
6868
- name: Checkout
6969
uses: actions/checkout@v2
@@ -94,7 +94,7 @@ jobs:
9494
9595
validate-query-help-files:
9696
name: Validate Query Help Files
97-
runs-on: ubuntu-latest
97+
runs-on: ubuntu-22.04
9898
steps:
9999
- name: Checkout
100100
uses: actions/checkout@v2
@@ -129,7 +129,7 @@ jobs:
129129
130130
validate-cpp-test-files:
131131
name: Validate C++ Test Files
132-
runs-on: ubuntu-latest
132+
runs-on: ubuntu-22.04
133133
steps:
134134
- name: Checkout
135135
uses: actions/checkout@v2
@@ -152,7 +152,7 @@ jobs:
152152
153153
validate-c-test-files:
154154
name: Validate C Test Files
155-
runs-on: ubuntu-latest
155+
runs-on: ubuntu-22.04
156156
steps:
157157
- name: Checkout
158158
uses: actions/checkout@v2
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ⚙️ Validate Rules CSV
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- "rc/**"
8+
- next
9+
pull_request:
10+
branches:
11+
- main
12+
- "rc/**"
13+
- next
14+
15+
16+
jobs:
17+
validate-rules-csv:
18+
name: Validate Rules CSV
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Check Rules
25+
shell: pwsh
26+
run: scripts/util/Get-DuplicateRules.ps1 -Language 'all' -CIMode
27+
28+

.vscode/tasks.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"type": "pickString",
186186
"options": [
187187
"Allocations",
188+
"Banned",
188189
"BannedFunctions",
189190
"BannedLibraries",
190191
"BannedSyntax",
@@ -222,6 +223,7 @@
222223
"Invariants",
223224
"Iterators",
224225
"Lambdas",
226+
"Language1",
225227
"Literals",
226228
"Loops",
227229
"Macros",

c/cert/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: cert-c-coding-standards
2-
version: 2.9.0-dev
2+
version: 2.11.0-dev
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# CON39-C: Do not join or detach a thread that was previously joined or detached
2+
3+
This query implements the CERT-C rule CON39-C:
4+
5+
> Do not join or detach a thread that was previously joined or detached
6+
7+
8+
## Description
9+
10+
The C Standard, 7.26.5.6 \[[ISO/IEC 9899:2011](https://wiki.sei.cmu.edu/confluence/display/c/AA.+Bibliography#AA.Bibliography-ISO-IEC9899-2011)\], states that a thread shall not be joined once it was previously joined or detached. Similarly, subclause 7.26.5.3 states that a thread shall not be detached once it was previously joined or detached. Violating either of these subclauses results in [undefined behavior](https://wiki.sei.cmu.edu/confluence/display/c/BB.+Definitions#BB.Definitions-undefinedbehavior).
11+
12+
## Noncompliant Code Example
13+
14+
This noncompliant code example detaches a thread that is later joined.
15+
16+
```cpp
17+
#include <stddef.h>
18+
#include <threads.h>
19+
20+
int thread_func(void *arg) {
21+
/* Do work */
22+
thrd_detach(thrd_current());
23+
return 0;
24+
}
25+
26+
int main(void) {
27+
thrd_t t;
28+
29+
if (thrd_success != thrd_create(&t, thread_func, NULL)) {
30+
/* Handle error */
31+
return 0;
32+
}
33+
34+
if (thrd_success != thrd_join(t, 0)) {
35+
/* Handle error */
36+
return 0;
37+
}
38+
return 0;
39+
}
40+
```
41+
42+
## Compliant Solution
43+
44+
This compliant solution does not detach the thread. Its resources are released upon successfully joining with the main thread:
45+
46+
```cpp
47+
#include <stddef.h>
48+
#include <threads.h>
49+
50+
int thread_func(void *arg) {
51+
/* Do work */
52+
return 0;
53+
}
54+
55+
int main(void) {
56+
thrd_t t;
57+
58+
if (thrd_success != thrd_create(&t, thread_func, NULL)) {
59+
/* Handle error */
60+
return 0;
61+
}
62+
63+
if (thrd_success != thrd_join(t, 0)) {
64+
/* Handle error */
65+
return 0;
66+
}
67+
return 0;
68+
}
69+
```
70+
71+
## Risk Assessment
72+
73+
Joining or detaching a previously joined or detached thread is [undefined behavior](https://wiki.sei.cmu.edu/confluence/display/c/BB.+Definitions#BB.Definitions-undefinedbehavior).
74+
75+
<table> <tbody> <tr> <th> Rule </th> <th> Severity </th> <th> Likelihood </th> <th> Remediation Cost </th> <th> Priority </th> <th> Level </th> </tr> <tr> <td> CON39-C </td> <td> Low </td> <td> Likely </td> <td> Medium </td> <td> <strong>P6</strong> </td> <td> <strong>L2</strong> </td> </tr> </tbody> </table>
76+
77+
78+
## Automated Detection
79+
80+
<table> <tbody> <tr> <th> Tool </th> <th> Version </th> <th> Checker </th> <th> Description </th> </tr> <tr> <td> <a> Astrée </a> </td> <td> 22.04 </td> <td> </td> <td> Supported, but no explicit checker </td> </tr> <tr> <td> <a> CodeSonar </a> </td> <td> 7.1p0 </td> <td> <strong>CONCURRENCY.TNJ</strong> </td> <td> Thread is not Joinable </td> </tr> <tr> <td> <a> Helix QAC </a> </td> <td> 2022.3 </td> <td> <strong>C1776</strong> </td> <td> </td> </tr> <tr> <td> <a> Parasoft C/C++test </a> </td> <td> 2022.1 </td> <td> <strong>CERT_C-CON39-a</strong> </td> <td> Do not join or detach a thread that was previously joined or detached </td> </tr> <tr> <td> <a> Polyspace Bug Finder </a> </td> <td> R2022b </td> <td> <a> CERT C: Rule CON39-C </a> </td> <td> Checks for join or detach of a joined or detached thread (rule fully covered) </td> </tr> </tbody> </table>
81+
82+
83+
## Related Vulnerabilities
84+
85+
Search for [vulnerabilities](https://wiki.sei.cmu.edu/confluence/display/c/BB.+Definitions#BB.Definitions-vulnerability) resulting from the violation of this rule on the [CERT website](https://www.kb.cert.org/vulnotes/bymetric?searchview&query=FIELD+KEYWORDS+contains+CON39-C).
86+
87+
## Bibliography
88+
89+
<table> <tbody> <tr> <td> \[ <a> ISO/IEC 9899:2011 </a> \] </td> <td> Subclause 7.26.5.3, "The <code>thrd_detach</code> Function" Subclause 7.26.5.6, "The <code>thrd_join</code> Function" </td> </tr> </tbody> </table>
90+
91+
92+
## Implementation notes
93+
94+
This query considers problematic usages of join and detach irrespective of the execution of the program and other synchronization and interprocess communication mechanisms that may be used.
95+
96+
## References
97+
98+
* CERT-C: [CON39-C: Do not join or detach a thread that was previously joined or detached](https://wiki.sei.cmu.edu/confluence/display/c)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @id c/cert/thread-was-previously-joined-or-detached
3+
* @name CON39-C: Do not join or detach a thread that was previously joined or detached
4+
* @description Joining or detaching a previously joined or detached thread can lead to undefined
5+
* program behavior.
6+
* @kind problem
7+
* @precision high
8+
* @problem.severity error
9+
* @tags external/cert/id/con39-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+
// OK
20+
// 1) Thread calls detach parent DOES NOT call join
21+
// 2) Parent calls join, thread does NOT call detach()
22+
// NOT OK
23+
// 1) Thread calls detach, parent calls join
24+
// 2) Thread calls detach twice, parent does not call join
25+
// 3) Parent calls join twice, thread does not call detach
26+
from C11ThreadCreateCall tcc
27+
where
28+
not isExcluded(tcc, Concurrency5Package::threadWasPreviouslyJoinedOrDetachedQuery()) and
29+
// Note: These cases can be simplified but they are presented like this for clarity
30+
// case 1 - calls to `thrd_join` and `thrd_detach` within the parent or
31+
// within the parent / child CFG.
32+
exists(C11ThreadWait tw, C11ThreadDetach dt |
33+
tw = getAThreadContextAwareSuccessor(tcc) and
34+
dt = getAThreadContextAwareSuccessor(tcc)
35+
)
36+
or
37+
// case 2 - multiple calls to `thrd_detach` within the threaded CFG.
38+
exists(C11ThreadDetach dt1, C11ThreadDetach dt2 |
39+
dt1 = getAThreadContextAwareSuccessor(tcc) and
40+
dt2 = getAThreadContextAwareSuccessor(tcc) and
41+
not dt1 = dt2
42+
)
43+
or
44+
// case 3 - multiple calls to `thrd_join` within the threaded CFG.
45+
exists(C11ThreadWait tw1, C11ThreadWait tw2 |
46+
tw1 = getAThreadContextAwareSuccessor(tcc) and
47+
tw2 = getAThreadContextAwareSuccessor(tcc) and
48+
not tw1 = tw2
49+
)
50+
select tcc, "Thread may call join or detach after the thread is joined or detached."

0 commit comments

Comments
 (0)