Skip to content

Commit af9ad7b

Browse files
committed
Merge branch 'main' into tuples
2 parents 645906a + 53b7584 commit af9ad7b

File tree

151 files changed

+3076
-358
lines changed

Some content is hidden

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

151 files changed

+3076
-358
lines changed

.github/workflows/compile-queries.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ jobs:
2424
run: |
2525
MERGE_BASE=$(git merge-base --fork-point origin/$BASE_BRANCH)
2626
echo "merge-base=$MERGE_BASE" >> $GITHUB_ENV
27-
- name: Calculate merge-base - branch
28-
if: ${{ github.event_name != 'pull_request' }}
29-
# using github.sha instead, since we're directly on a branch, and not in a PR
30-
run: |
31-
MERGE_BASE=${{ github.sha }}
32-
echo "merge-base=$MERGE_BASE" >> $GITHUB_ENV
33-
- name: Cache CodeQL query compilation
27+
- name: Read CodeQL query compilation - PR
28+
if: ${{ github.event_name == 'pull_request' }}
3429
uses: actions/cache@v3
3530
with:
3631
path: '*/ql/src/.cache'
37-
# current GH HEAD first, merge-base second, generic third
38-
key: codeql-stable-compile-${{ github.sha }}
32+
key: codeql-compile-pr-${{ github.sha }} # deliberately not using the `compile-compile-main` keys here.
3933
restore-keys: |
40-
codeql-stable-compile-${{ env.merge-base }}
41-
codeql-stable-compile-
34+
codeql-compile-main-${{ env.merge-base }}
35+
codeql-compile-main-
36+
- name: Fill CodeQL query compilation cache - main
37+
if: ${{ github.event_name != 'pull_request' }}
38+
uses: actions/cache@v3
39+
with:
40+
path: '*/ql/src/.cache'
41+
key: codeql-compile-main-${{ github.sha }} # just fill on main
4242
- name: Setup CodeQL
4343
uses: ./.github/actions/fetch-codeql
4444
with:

.github/workflows/swift.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ jobs:
5151
- uses: actions/checkout@v3
5252
- uses: ./swift/actions/create-extractor-pack
5353
- uses: ./swift/actions/run-quick-tests
54+
- uses: ./swift/actions/print-unextracted
5455
build-and-test-linux:
5556
runs-on: ubuntu-20.04
5657
steps:
5758
- uses: actions/checkout@v3
5859
- uses: ./swift/actions/create-extractor-pack
5960
- uses: ./swift/actions/run-quick-tests
61+
- uses: ./swift/actions/print-unextracted
6062
qltests-linux:
6163
needs: build-and-test-linux
6264
runs-on: ubuntu-latest

cpp/ql/lib/semmle/code/cpp/models/implementations/Strcat.qll

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
5050
}
5151

5252
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
53-
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
54-
input.isParameter(2) and
55-
output.isParameterDeref(0)
56-
or
57-
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and
58-
input.isParameter(3) and
59-
output.isParameterDeref(0)
60-
or
61-
input.isParameterDeref(0) and
62-
output.isParameterDeref(0)
63-
or
64-
input.isParameterDeref(1) and
65-
output.isParameterDeref(0)
53+
(
54+
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
55+
input.isParameter(2)
56+
or
57+
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and
58+
input.isParameter(3)
59+
or
60+
input.isParameterDeref(0)
61+
or
62+
input.isParameterDeref(1)
63+
) and
64+
(output.isParameterDeref(0) or output.isReturnValueDeref())
6665
}
6766

6867
override predicate hasArrayInput(int param) {

cpp/ql/src/Likely Bugs/Format/TooManyFormatArguments.ql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313

1414
import cpp
1515

16-
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given
16+
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given, string ffcName
1717
where
1818
ffc = fl.getUse() and
1919
expected = fl.getNumArgNeeded() and
2020
given = ffc.getNumFormatArgument() and
2121
expected < given and
22-
fl.specsAreKnown()
23-
select ffc, "Format expects " + expected.toString() + " arguments but given " + given.toString()
22+
fl.specsAreKnown() and
23+
(
24+
if ffc.isInMacroExpansion()
25+
then ffcName = ffc.getTarget().getName() + " (in a macro expansion)"
26+
else ffcName = ffc.getTarget().getName()
27+
)
28+
select ffc,
29+
"Format for " + ffcName + " expects " + expected.toString() + " arguments but given " +
30+
given.toString()

cpp/ql/src/Likely Bugs/Format/WrongNumberOfFormatArguments.ql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616

1717
import cpp
1818

19-
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given
19+
from FormatLiteral fl, FormattingFunctionCall ffc, int expected, int given, string ffcName
2020
where
2121
ffc = fl.getUse() and
2222
expected = fl.getNumArgNeeded() and
2323
given = ffc.getNumFormatArgument() and
2424
expected > given and
25-
fl.specsAreKnown()
26-
select ffc, "Format expects " + expected.toString() + " arguments but given " + given.toString()
25+
fl.specsAreKnown() and
26+
(
27+
if ffc.isInMacroExpansion()
28+
then ffcName = ffc.getTarget().getName() + " (in a macro expansion)"
29+
else ffcName = ffc.getTarget().getName()
30+
)
31+
select ffc,
32+
"Format for " + ffcName + " expects " + expected.toString() + " arguments but given " +
33+
given.toString()

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,7 @@ postWithInFlow
8787
| test.cpp:465:3:465:4 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
8888
| test.cpp:465:4:465:4 | p [inner post update] | PostUpdateNode should not be the target of local flow. |
8989
| test.cpp:470:22:470:22 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
90+
| test.cpp:499:3:499:4 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
91+
| test.cpp:499:4:499:4 | p [inner post update] | PostUpdateNode should not be the target of local flow. |
92+
| test.cpp:505:35:505:35 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
9093
viableImplInCallContextTooLarge

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ postWithInFlow
582582
| test.cpp:489:7:489:7 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
583583
| test.cpp:491:5:491:5 | x [post update] | PostUpdateNode should not be the target of local flow. |
584584
| test.cpp:494:5:494:5 | x [post update] | PostUpdateNode should not be the target of local flow. |
585+
| test.cpp:499:3:499:4 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
586+
| test.cpp:499:4:499:4 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
587+
| test.cpp:499:4:499:4 | p [post update] | PostUpdateNode should not be the target of local flow. |
588+
| test.cpp:504:7:504:7 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
589+
| test.cpp:505:34:505:35 | & ... [post update] | PostUpdateNode should not be the target of local flow. |
590+
| test.cpp:505:34:505:35 | & ... [post update] | PostUpdateNode should not be the target of local flow. |
591+
| test.cpp:505:35:505:35 | x [post update] | PostUpdateNode should not be the target of local flow. |
585592
| true_upon_entry.cpp:9:7:9:7 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
586593
| true_upon_entry.cpp:10:12:10:12 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
587594
| true_upon_entry.cpp:10:27:10:27 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,14 @@ void regression_with_phi_flow(int clean1) {
494494
x = source();
495495
}
496496
}
497+
498+
int intOutparamSourceMissingReturn(int *p) {
499+
*p = source();
500+
// return deliberately omitted to test IR dataflow behavior
501+
}
502+
503+
void viaOutparamMissingReturn() {
504+
int x = 0;
505+
intOutparamSourceMissingReturn(&x);
506+
sink(x); // $ ast,ir
507+
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/true_upon_entry.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ int source();
55
void sink(...);
66
bool random();
77

8-
int test1() {
8+
void test1() {
99
int x = source();
1010
for (int i = 0; i < 10; i++) {
1111
x = 0;
1212
}
1313
sink(x); // $ SPURIOUS: ir
1414
}
1515

16-
int test2(int iterations) {
16+
void test2(int iterations) {
1717
int x = source();
1818
for (int i = 0; i < iterations; i++) {
1919
x = 0;
2020
}
2121
sink(x); // $ ast,ir
2222
}
2323

24-
int test3() {
24+
void test3() {
2525
int x = 0;
2626
for (int i = 0; i < 10; i++) {
2727
x = source();
2828
}
2929
sink(x); // $ ast,ir
3030
}
3131

32-
int test4() {
32+
void test4() {
3333
int x = source();
3434
for (int i = 0; i < 10; i++) {
3535
if (random())
@@ -39,7 +39,7 @@ int test4() {
3939
sink(x); // $ ast,ir
4040
}
4141

42-
int test5() {
42+
void test5() {
4343
int x = source();
4444
for (int i = 0; i < 10; i++) {
4545
if (random())
@@ -49,15 +49,15 @@ int test5() {
4949
sink(x); // $ ast,ir
5050
}
5151

52-
int test6() {
52+
void test6() {
5353
int y;
5454
int x = source();
5555
for (int i = 0; i < 10 && (y = 1); i++) {
5656
}
5757
sink(x); // $ ast,ir
5858
}
5959

60-
int test7() {
60+
void test7() {
6161
int y;
6262
int x = source();
6363
for (int i = 0; i < 10 && (y = 1); i++) {
@@ -66,7 +66,7 @@ int test7() {
6666
sink(x); // $ SPURIOUS: ir
6767
}
6868

69-
int test8() {
69+
void test8() {
7070
int x = source();
7171
// It appears to the analysis that the condition can exit after `i < 10`
7272
// without having assigned to `x`. That is an effect of how the
@@ -78,29 +78,29 @@ int test8() {
7878
sink(x); // $ SPURIOUS: ast,ir
7979
}
8080

81-
int test9() {
81+
void test9() {
8282
int y;
8383
int x = source();
8484
for (int i = 0; (y = 1) && i < 10; i++) {
8585
}
8686
sink(x); // $ ast,ir
8787
}
8888

89-
int test10() {
89+
void test10() {
9090
int x = source();
9191
for (int i = 0; (x = 1) && i < 10; i++) {
9292
}
9393
sink(x); // no flow
9494
}
9595

96-
int test10(int b, int d) {
96+
void test10(int b, int d) {
9797
int i = 0;
9898
int x = source();
9999
if (b)
100100
goto L;
101101
for (; i < 10; i += d) {
102102
x = 0;
103-
L:
103+
L: ;
104104
}
105105
sink(x); // $ ir MISSING: ast
106106
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5964,6 +5964,7 @@
59645964
| taint.cpp:172:10:172:15 | buffer | taint.cpp:172:3:172:8 | call to strcat | |
59655965
| taint.cpp:172:10:172:15 | buffer | taint.cpp:172:10:172:15 | ref arg buffer | TAINT |
59665966
| taint.cpp:172:10:172:15 | ref arg buffer | taint.cpp:173:8:173:13 | buffer | |
5967+
| taint.cpp:172:18:172:24 | tainted | taint.cpp:172:3:172:8 | call to strcat | TAINT |
59675968
| taint.cpp:172:18:172:24 | tainted | taint.cpp:172:10:172:15 | ref arg buffer | TAINT |
59685969
| taint.cpp:180:19:180:19 | p | taint.cpp:180:19:180:19 | p | |
59695970
| taint.cpp:180:19:180:19 | p | taint.cpp:181:9:181:9 | p | |
@@ -6373,12 +6374,14 @@
63736374
| taint.cpp:561:9:561:13 | dest1 | taint.cpp:561:9:561:13 | ref arg dest1 | TAINT |
63746375
| taint.cpp:561:9:561:13 | ref arg dest1 | taint.cpp:560:24:560:28 | dest1 | |
63756376
| taint.cpp:561:9:561:13 | ref arg dest1 | taint.cpp:562:7:562:11 | dest1 | |
6377+
| taint.cpp:561:16:561:21 | source | taint.cpp:561:2:561:7 | call to strcat | TAINT |
63766378
| taint.cpp:561:16:561:21 | source | taint.cpp:561:9:561:13 | ref arg dest1 | TAINT |
63776379
| taint.cpp:562:7:562:11 | ref arg dest1 | taint.cpp:560:24:560:28 | dest1 | |
63786380
| taint.cpp:564:9:564:13 | dest2 | taint.cpp:564:2:564:7 | call to strcat | |
63796381
| taint.cpp:564:9:564:13 | dest2 | taint.cpp:564:9:564:13 | ref arg dest2 | TAINT |
63806382
| taint.cpp:564:9:564:13 | ref arg dest2 | taint.cpp:560:37:560:41 | dest2 | |
63816383
| taint.cpp:564:9:564:13 | ref arg dest2 | taint.cpp:565:7:565:11 | dest2 | |
6384+
| taint.cpp:564:16:564:20 | clean | taint.cpp:564:2:564:7 | call to strcat | TAINT |
63826385
| taint.cpp:564:16:564:20 | clean | taint.cpp:564:9:564:13 | ref arg dest2 | TAINT |
63836386
| taint.cpp:565:7:565:11 | ref arg dest2 | taint.cpp:560:37:560:41 | dest2 | |
63846387
| taint.cpp:572:37:572:41 | dest1 | taint.cpp:572:37:572:41 | dest1 | |
@@ -6405,9 +6408,12 @@
64056408
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:572:37:572:41 | dest1 | |
64066409
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:575:7:575:11 | dest1 | |
64076410
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:576:8:576:12 | dest1 | |
6411+
| taint.cpp:574:43:574:45 | ptr | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64086412
| taint.cpp:574:43:574:45 | ptr | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
6413+
| taint.cpp:574:48:574:48 | n | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64096414
| taint.cpp:574:48:574:48 | n | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
64106415
| taint.cpp:574:51:574:56 | ref arg source | taint.cpp:573:49:573:54 | source | |
6416+
| taint.cpp:574:51:574:56 | source | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64116417
| taint.cpp:574:51:574:56 | source | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
64126418
| taint.cpp:575:7:575:11 | ref arg dest1 | taint.cpp:572:37:572:41 | dest1 | |
64136419
| taint.cpp:575:7:575:11 | ref arg dest1 | taint.cpp:576:8:576:12 | dest1 | |
@@ -6421,8 +6427,11 @@
64216427
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:572:85:572:89 | dest3 | |
64226428
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:581:7:581:11 | dest3 | |
64236429
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:582:8:582:12 | dest3 | |
6430+
| taint.cpp:580:43:580:45 | ptr | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64246431
| taint.cpp:580:43:580:45 | ptr | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
6432+
| taint.cpp:580:48:580:48 | n | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64256433
| taint.cpp:580:48:580:48 | n | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
6434+
| taint.cpp:580:51:580:55 | clean | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64266435
| taint.cpp:580:51:580:55 | clean | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
64276436
| taint.cpp:580:51:580:55 | ref arg clean | taint.cpp:573:32:573:36 | clean | |
64286437
| taint.cpp:581:7:581:11 | ref arg dest3 | taint.cpp:572:85:572:89 | dest3 | |

0 commit comments

Comments
 (0)