Skip to content

Commit ca67e45

Browse files
authored
Merge branch 'main' into openssl-signatures
2 parents 5dbaf1b + 0ef17ba commit ca67e45

File tree

10 files changed

+324
-96
lines changed

10 files changed

+324
-96
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added a predicate `getReferencedMember` to `UsingDeclarationEntry`, which yields a member depending on a type template parameter.

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ class EVP_Cipher_Final_Call extends EVPFinal, EVP_Cipher_Operation {
7474
or
7575
result = EVP_Cipher_Operation.super.getOutputArg()
7676
}
77-
}
77+
}

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPHashOperation.qll

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,84 @@
22
* https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
33
*/
44

5-
private import experimental.quantum.Language
6-
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow
7-
private import OpenSSLOperationBase
8-
private import EVPHashInitializer
9-
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
10-
11-
class EVP_Digest_Update_Call extends EVPUpdate {
12-
EVP_Digest_Update_Call() { this.(Call).getTarget().getName() = "EVP_DigestUpdate" }
13-
14-
override Expr getInputArg() { result = this.(Call).getArgument(1) }
15-
}
16-
17-
//https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
18-
class EVP_Q_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance {
19-
EVP_Q_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Q_digest" }
20-
21-
override Expr getAlgorithmArg() { result = this.(Call).getArgument(1) }
22-
23-
override EVP_Hash_Initializer getInitCall() {
24-
// This variant of digest does not use an init
25-
// and even if it were used, the init would be ignored/undefined
26-
none()
27-
}
28-
29-
override Expr getInputArg() { result = this.(Call).getArgument(3) }
30-
31-
override Expr getOutputArg() { result = this.(Call).getArgument(5) }
32-
33-
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
34-
result = EVPOperation.super.getOutputArtifact()
35-
}
36-
37-
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
38-
result = EVPOperation.super.getInputConsumer()
39-
}
40-
}
41-
42-
class EVP_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance {
43-
EVP_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Digest" }
44-
45-
// There is no context argument for this function
46-
override Expr getContextArg() { none() }
47-
48-
override Expr getAlgorithmArg() { result = this.(Call).getArgument(4) }
49-
50-
override EVP_Hash_Initializer getInitCall() {
51-
// This variant of digest does not use an init
52-
// and even if it were used, the init would be ignored/undefined
53-
none()
54-
}
55-
56-
override Expr getInputArg() { result = this.(Call).getArgument(0) }
57-
58-
override Expr getOutputArg() { result = this.(Call).getArgument(2) }
59-
60-
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
61-
result = EVPOperation.super.getOutputArtifact()
62-
}
63-
64-
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
65-
result = EVPOperation.super.getInputConsumer()
66-
}
67-
}
68-
69-
class EVP_Digest_Final_Call extends EVPFinal, Crypto::HashOperationInstance {
70-
EVP_Digest_Final_Call() {
71-
this.(Call).getTarget().getName() in [
72-
"EVP_DigestFinal", "EVP_DigestFinal_ex", "EVP_DigestFinalXOF"
73-
]
74-
}
75-
76-
override Expr getOutputArg() { result = this.(Call).getArgument(1) }
77-
78-
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
79-
result = EVPFinal.super.getOutputArtifact()
80-
}
81-
82-
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
83-
result = EVPFinal.super.getInputConsumer()
84-
}
85-
}
5+
private import experimental.quantum.Language
6+
private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow
7+
private import OpenSSLOperationBase
8+
private import EVPHashInitializer
9+
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
10+
11+
class EVP_Digest_Update_Call extends EVPUpdate {
12+
EVP_Digest_Update_Call() { this.(Call).getTarget().getName() = "EVP_DigestUpdate" }
13+
14+
override Expr getInputArg() { result = this.(Call).getArgument(1) }
15+
}
16+
17+
//https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
18+
class EVP_Q_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance {
19+
EVP_Q_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Q_digest" }
20+
21+
override Expr getAlgorithmArg() { result = this.(Call).getArgument(1) }
22+
23+
override EVP_Hash_Initializer getInitCall() {
24+
// This variant of digest does not use an init
25+
// and even if it were used, the init would be ignored/undefined
26+
none()
27+
}
28+
29+
override Expr getInputArg() { result = this.(Call).getArgument(3) }
30+
31+
override Expr getOutputArg() { result = this.(Call).getArgument(5) }
32+
33+
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
34+
result = EVPOperation.super.getOutputArtifact()
35+
}
36+
37+
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
38+
result = EVPOperation.super.getInputConsumer()
39+
}
40+
}
41+
42+
class EVP_Digest_Operation extends EVPOperation, Crypto::HashOperationInstance {
43+
EVP_Digest_Operation() { this.(Call).getTarget().getName() = "EVP_Digest" }
44+
45+
// There is no context argument for this function
46+
override Expr getContextArg() { none() }
47+
48+
override Expr getAlgorithmArg() { result = this.(Call).getArgument(4) }
49+
50+
override EVP_Hash_Initializer getInitCall() {
51+
// This variant of digest does not use an init
52+
// and even if it were used, the init would be ignored/undefined
53+
none()
54+
}
55+
56+
override Expr getInputArg() { result = this.(Call).getArgument(0) }
57+
58+
override Expr getOutputArg() { result = this.(Call).getArgument(2) }
59+
60+
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
61+
result = EVPOperation.super.getOutputArtifact()
62+
}
63+
64+
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
65+
result = EVPOperation.super.getInputConsumer()
66+
}
67+
}
68+
69+
class EVP_Digest_Final_Call extends EVPFinal, Crypto::HashOperationInstance {
70+
EVP_Digest_Final_Call() {
71+
this.(Call).getTarget().getName() in [
72+
"EVP_DigestFinal", "EVP_DigestFinal_ex", "EVP_DigestFinalXOF"
73+
]
74+
}
75+
76+
override Expr getOutputArg() { result = this.(Call).getArgument(1) }
77+
78+
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
79+
result = EVPFinal.super.getOutputArtifact()
80+
}
81+
82+
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
83+
result = EVPFinal.super.getInputConsumer()
84+
}
85+
}

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperationBase.qll

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgor
88
class OpenSSLCall extends Call { }
99

1010
/**
11-
* All OpenSSL operations.
11+
* A class for all OpenSSL operations.
1212
*/
1313
abstract class OpenSSLOperation extends Crypto::OperationInstance instanceof OpenSSLCall {
1414
/**
@@ -37,12 +37,12 @@ abstract class OpenSSLOperation extends Crypto::OperationInstance instanceof Ope
3737
*/
3838
abstract class EVPInitialize extends OpenSSLCall {
3939
/**
40-
* The context argument that ties together initialization, updates and/or final calls.
40+
* Gets the context argument that ties together initialization, updates and/or final calls.
4141
*/
4242
Expr getContextArg() { result = this.(Call).getArgument(0) }
4343

4444
/**
45-
* The type of key operation, none if not applicable.
45+
* Gets the type of key operation, none if not applicable.
4646
*/
4747
Crypto::KeyOperationSubtype getKeyOperationSubtype() { none() }
4848

@@ -54,12 +54,12 @@ abstract class EVPInitialize extends OpenSSLCall {
5454
Expr getAlgorithmArg() { none() }
5555

5656
/**
57-
* The key for the operation, none if not applicable.
57+
* Gets the key for the operation, none if not applicable.
5858
*/
5959
Expr getKeyArg() { none() }
6060

6161
/**
62-
* The IV/nonce, none if not applicable.
62+
* Gets the IV/nonce, none if not applicable.
6363
*/
6464
Expr getIVArg() { none() }
6565
}
@@ -71,7 +71,7 @@ abstract class EVPInitialize extends OpenSSLCall {
7171
*/
7272
abstract class EVPUpdate extends OpenSSLCall {
7373
/**
74-
* The context argument that ties together initialization, updates and/or final calls.
74+
* Gets the context argument that ties together initialization, updates and/or final calls.
7575
*/
7676
Expr getContextArg() { result = this.(Call).getArgument(0) }
7777

@@ -108,7 +108,7 @@ private module AlgGetterToAlgConsumerFlow = DataFlow::Global<AlgGetterToAlgConsu
108108
*/
109109
abstract class EVPOperation extends OpenSSLOperation {
110110
/**
111-
* The context argument that ties together initialization, updates and/or final calls.
111+
* Gets the context argument that ties together initialization, updates and/or final calls.
112112
*/
113113
Expr getContextArg() { result = this.(Call).getArgument(0) }
114114

@@ -126,9 +126,7 @@ abstract class EVPOperation extends OpenSSLOperation {
126126
/**
127127
* Overwrite with an explicitly specified algorithm or leave base implementation to find it in the initialization call.
128128
*/
129-
override Expr getAlgorithmArg() {
130-
if exists(this.getInitCall()) then result = this.getInitCall().getAlgorithmArg() else none()
131-
}
129+
override Expr getAlgorithmArg() { result = this.getInitCall().getAlgorithmArg() }
132130

133131
/**
134132
* Finds the initialization call, may be none.
@@ -165,13 +163,13 @@ abstract class EVPFinal extends EVPOperation {
165163
}
166164

167165
/**
168-
* The input data was provided to all update calls.
166+
* Gets the input data provided to all update calls.
169167
* If more input data was provided in the final call, override the method.
170168
*/
171169
override Expr getInputArg() { result = this.getUpdateCalls().getInputArg() }
172170

173171
/**
174-
* The output data was provided to all update calls.
172+
* Gets the output data provided to all update calls.
175173
* If more output data was provided in the final call, override the method.
176174
*/
177175
override Expr getOutputArg() { result = this.getUpdateCalls().getOutputArg() }

cpp/ql/lib/semmle/code/cpp/Namespace.qll

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,27 @@ class UsingDeclarationEntry extends UsingEntry {
174174
*/
175175
Declaration getDeclaration() { usings(underlyingElement(this), unresolveElement(result), _, _) }
176176

177-
override string toString() { result = "using " + this.getDeclaration().getDescription() }
177+
/**
178+
* Gets the member that is referenced by this using declaration, where the member depends on a
179+
* type template parameter.
180+
*
181+
* For example:
182+
* ```
183+
* template <typename T>
184+
* class A {
185+
* using T::m;
186+
* };
187+
* ```
188+
* Here, `getReferencedMember()` yields the member `m` of `T`. Observe that,
189+
* as `T` is not instantiated, `m` is represented by a `Literal` and not
190+
* a `Declaration`.
191+
*/
192+
Literal getReferencedMember() { usings(underlyingElement(this), unresolveElement(result), _, _) }
193+
194+
override string toString() {
195+
result = "using " + this.getDeclaration().getDescription() or
196+
result = "using " + this.getReferencedMember()
197+
}
178198
}
179199

180200
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| openssl_basic.c:133:13:133:30 | HashOperation | openssl_basic.c:133:39:133:44 | Digest | openssl_basic.c:125:38:125:47 | HashAlgorithm | openssl_basic.c:129:37:129:43 | Message |
2-
| openssl_basic.c:153:13:153:22 | HashOperation | openssl_basic.c:153:46:153:51 | Digest | openssl_basic.c:153:67:153:73 | HashAlgorithm | openssl_basic.c:153:24:153:30 | Message |
2+
| openssl_basic.c:153:13:153:22 | HashOperation | openssl_basic.c:153:46:153:51 | Digest | openssl_basic.c:153:67:153:73 | HashAlgorithm | openssl_basic.c:153:24:153:30 | Message |

cpp/ql/test/library-tests/comments/binding/commentBinding.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
| multi.c:5:27:5:36 | // Multi 3 | declaration of multi3 |
1010
| templates.cpp:3:3:3:8 | // Foo | declaration of foo |
1111
| templates.cpp:7:3:7:8 | // Bar | definition of bar |
12+
| templates.cpp:16:3:16:20 | // using T::member | using member |
13+
| templates.cpp:19:3:19:28 | // using T::nested::member | using member |
14+
| templates.cpp:25:3:25:20 | // using T::member | using member |

cpp/ql/test/library-tests/comments/binding/templates.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ class Cl {
1010
}
1111
};
1212

13+
14+
template <typename T>
15+
class Derived : public T {
16+
// using T::member
17+
using T::member;
18+
19+
// using T::nested::member
20+
using T::nested::member;
21+
};
22+
23+
template <typename T>
24+
class Base {
25+
// using T::member
26+
using T::member;
27+
};

0 commit comments

Comments
 (0)