Skip to content

Commit 0d27d63

Browse files
committed
Merge remote-tracking branch 'upstream/main' into mathiasvp/replace-ast-with-ir-use-usedataflow
2 parents 4c308d9 + 50c2683 commit 0d27d63

File tree

111 files changed

+1706
-455
lines changed

Some content is hidden

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

111 files changed

+1706
-455
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/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()
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
| a.c:18:3:18:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
2-
| b.c:15:3:15:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
3-
| c.c:7:3:7:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 2 |
4-
| custom_printf.cpp:31:5:31:12 | call to myPrintf | Format expects 2 arguments but given 3 |
5-
| macros.cpp:12:2:12:31 | call to printf | Format expects 2 arguments but given 3 |
6-
| macros.cpp:16:2:16:30 | call to printf | Format expects 2 arguments but given 3 |
7-
| test.c:7:2:7:7 | call to printf | Format expects 0 arguments but given 1 |
8-
| test.c:21:2:21:7 | call to printf | Format expects 2 arguments but given 3 |
9-
| test.c:27:3:27:8 | call to printf | Format expects 2 arguments but given 3 |
10-
| test.c:31:3:31:8 | call to printf | Format expects 1 arguments but given 3 |
11-
| test.c:32:3:32:8 | call to printf | Format expects 1 arguments but given 2 |
12-
| test.c:39:3:39:8 | call to printf | Format expects 2 arguments but given 5 |
13-
| test.c:40:3:40:8 | call to printf | Format expects 2 arguments but given 4 |
14-
| test.c:41:3:41:8 | call to printf | Format expects 2 arguments but given 3 |
1+
| a.c:18:3:18:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
2+
| b.c:15:3:15:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
3+
| c.c:7:3:7:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 2 |
4+
| custom_printf.cpp:31:5:31:12 | call to myPrintf | Format for myPrintf expects 2 arguments but given 3 |
5+
| macros.cpp:12:2:12:31 | call to printf | Format for printf (in a macro expansion) expects 2 arguments but given 3 |
6+
| macros.cpp:16:2:16:30 | call to printf | Format for printf (in a macro expansion) expects 2 arguments but given 3 |
7+
| test.c:7:2:7:7 | call to printf | Format for printf expects 0 arguments but given 1 |
8+
| test.c:21:2:21:7 | call to printf | Format for printf expects 2 arguments but given 3 |
9+
| test.c:27:3:27:8 | call to printf | Format for printf expects 2 arguments but given 3 |
10+
| test.c:31:3:31:8 | call to printf | Format for printf expects 1 arguments but given 3 |
11+
| test.c:32:3:32:8 | call to printf | Format for printf expects 1 arguments but given 2 |
12+
| test.c:39:3:39:8 | call to printf | Format for printf expects 2 arguments but given 5 |
13+
| test.c:40:3:40:8 | call to printf | Format for printf expects 2 arguments but given 4 |
14+
| test.c:41:3:41:8 | call to printf | Format for printf expects 2 arguments but given 3 |
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
| a.c:16:3:16:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
2-
| b.c:13:3:13:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
3-
| c.c:5:3:5:25 | call to myMultiplyDefinedPrintf | Format expects 1 arguments but given 0 |
4-
| custom_printf.cpp:29:5:29:12 | call to myPrintf | Format expects 2 arguments but given 1 |
5-
| macros.cpp:14:2:14:37 | call to printf | Format expects 4 arguments but given 3 |
6-
| macros.cpp:21:2:21:36 | call to printf | Format expects 4 arguments but given 3 |
7-
| test.c:9:2:9:7 | call to printf | Format expects 1 arguments but given 0 |
8-
| test.c:12:2:12:7 | call to printf | Format expects 2 arguments but given 1 |
9-
| test.c:15:2:15:7 | call to printf | Format expects 3 arguments but given 2 |
10-
| test.c:19:2:19:7 | call to printf | Format expects 2 arguments but given 1 |
11-
| test.c:29:3:29:8 | call to printf | Format expects 2 arguments but given 1 |
1+
| a.c:16:3:16:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
2+
| b.c:13:3:13:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
3+
| c.c:5:3:5:25 | call to myMultiplyDefinedPrintf | Format for myMultiplyDefinedPrintf expects 1 arguments but given 0 |
4+
| custom_printf.cpp:29:5:29:12 | call to myPrintf | Format for myPrintf expects 2 arguments but given 1 |
5+
| macros.cpp:14:2:14:37 | call to printf | Format for printf (in a macro expansion) expects 4 arguments but given 3 |
6+
| macros.cpp:21:2:21:36 | call to printf | Format for printf (in a macro expansion) expects 4 arguments but given 3 |
7+
| macros.cpp:32:2:32:25 | call to printf | Format for printf (in a macro expansion) expects 1 arguments but given 0 |
8+
| test.c:9:2:9:7 | call to printf | Format for printf expects 1 arguments but given 0 |
9+
| test.c:12:2:12:7 | call to printf | Format for printf expects 2 arguments but given 1 |
10+
| test.c:15:2:15:7 | call to printf | Format for printf expects 3 arguments but given 2 |
11+
| test.c:19:2:19:7 | call to printf | Format for printf expects 2 arguments but given 1 |
12+
| test.c:29:3:29:8 | call to printf | Format for printf expects 2 arguments but given 1 |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongNumberOfFormatArguments/macros.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ void testMacros(int a, int b, int c)
1313
GOODPRINTF("%i %i %i\n", a, b, c); // GOOD
1414
GOODPRINTF("%i %i %i %i\n", a, b, c); // BAD: too few format arguments
1515

16-
BADPRINTF("%i %i\n", a, b, 0); // BAD: too many format arguments
16+
BADPRINTF("%i %i\n", a, b, 0); // DUBIOUS: too many format arguments
1717
// ^ here there are too many format arguments, but the design of the Macro forces the user
1818
// to do this, and the extra argument is harmlessly ignored in practice. Reporting these
1919
// results can be extremely noisy (e.g. in openldap).
2020
BADPRINTF("%i %i %i\n", a, b, c); // GOOD
2121
BADPRINTF("%i %i %i %i\n", a, b, c); // BAD: too few format arguments
2222
}
23+
24+
#define DOTHING(x) \
25+
printf("doing thing: " #x); x
26+
27+
void testMacros2()
28+
{
29+
int x;
30+
31+
DOTHING(x++); // GOOD
32+
DOTHING(printf("%i", x)); // BAD: the printf inside the macro has too few format arguments
33+
}

java/ql/lib/semmle/code/java/security/Encryption.qll

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ class KeyPairGenerator extends RefType {
8888
KeyPairGenerator() { this.hasQualifiedName("java.security", "KeyPairGenerator") }
8989
}
9090

91+
/** The `init` method declared in `javax.crypto.KeyGenerator`. */
92+
class KeyGeneratorInitMethod extends Method {
93+
KeyGeneratorInitMethod() {
94+
this.getDeclaringType() instanceof KeyGenerator and
95+
this.hasName("init")
96+
}
97+
}
98+
99+
/** The `initialize` method declared in `java.security.KeyPairGenerator`. */
100+
class KeyPairGeneratorInitMethod extends Method {
101+
KeyPairGeneratorInitMethod() {
102+
this.getDeclaringType() instanceof KeyPairGenerator and
103+
this.hasName("initialize")
104+
}
105+
}
106+
91107
/** The `verify` method of the class `javax.net.ssl.HostnameVerifier`. */
92108
class HostnameVerifierVerify extends Method {
93109
HostnameVerifierVerify() {
@@ -367,8 +383,8 @@ class JavaSecuritySignature extends JavaSecurityAlgoSpec {
367383
override Expr getAlgoSpec() { result = this.(ConstructorCall).getArgument(0) }
368384
}
369385

370-
/** A method call to the Java class `java.security.KeyPairGenerator`. */
371-
class JavaSecurityKeyPairGenerator extends JavaxCryptoAlgoSpec {
386+
/** A call to the `getInstance` method declared in `java.security.KeyPairGenerator`. */
387+
class JavaSecurityKeyPairGenerator extends JavaSecurityAlgoSpec {
372388
JavaSecurityKeyPairGenerator() {
373389
exists(Method m | m.getAReference() = this |
374390
m.getDeclaringType() instanceof KeyPairGenerator and
@@ -378,3 +394,53 @@ class JavaSecurityKeyPairGenerator extends JavaxCryptoAlgoSpec {
378394

379395
override Expr getAlgoSpec() { result = this.(MethodAccess).getArgument(0) }
380396
}
397+
398+
/** The Java class `java.security.AlgorithmParameterGenerator`. */
399+
class AlgorithmParameterGenerator extends RefType {
400+
AlgorithmParameterGenerator() {
401+
this.hasQualifiedName("java.security", "AlgorithmParameterGenerator")
402+
}
403+
}
404+
405+
/** The `init` method declared in `java.security.AlgorithmParameterGenerator`. */
406+
class AlgoParamGeneratorInitMethod extends Method {
407+
AlgoParamGeneratorInitMethod() {
408+
this.getDeclaringType() instanceof AlgorithmParameterGenerator and
409+
this.hasName("init")
410+
}
411+
}
412+
413+
/** A call to the `getInstance` method declared in `java.security.AlgorithmParameterGenerator`. */
414+
class JavaSecurityAlgoParamGenerator extends JavaSecurityAlgoSpec {
415+
JavaSecurityAlgoParamGenerator() {
416+
exists(Method m | m.getAReference() = this |
417+
m.getDeclaringType() instanceof AlgorithmParameterGenerator and
418+
m.getName() = "getInstance"
419+
)
420+
}
421+
422+
override Expr getAlgoSpec() { result = this.(MethodAccess).getArgument(0) }
423+
}
424+
425+
/** An implementation of the `java.security.spec.AlgorithmParameterSpec` interface. */
426+
abstract class AlgorithmParameterSpec extends RefType { }
427+
428+
/** The Java class `java.security.spec.ECGenParameterSpec`. */
429+
class EcGenParameterSpec extends AlgorithmParameterSpec {
430+
EcGenParameterSpec() { this.hasQualifiedName("java.security.spec", "ECGenParameterSpec") }
431+
}
432+
433+
/** The Java class `java.security.spec.RSAKeyGenParameterSpec`. */
434+
class RsaKeyGenParameterSpec extends AlgorithmParameterSpec {
435+
RsaKeyGenParameterSpec() { this.hasQualifiedName("java.security.spec", "RSAKeyGenParameterSpec") }
436+
}
437+
438+
/** The Java class `java.security.spec.DSAGenParameterSpec`. */
439+
class DsaGenParameterSpec extends AlgorithmParameterSpec {
440+
DsaGenParameterSpec() { this.hasQualifiedName("java.security.spec", "DSAGenParameterSpec") }
441+
}
442+
443+
/** The Java class `javax.crypto.spec.DHGenParameterSpec`. */
444+
class DhGenParameterSpec extends AlgorithmParameterSpec {
445+
DhGenParameterSpec() { this.hasQualifiedName("javax.crypto.spec", "DHGenParameterSpec") }
446+
}

0 commit comments

Comments
 (0)