Skip to content

Commit d9bdb2c

Browse files
authored
Merge pull request #2274 from geoffw0/oddsends
CPP: Clean up new queries and libraries
2 parents e576395 + 58b6fc6 commit d9bdb2c

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

cpp/ql/src/Microsoft/SAL.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class SALParameter extends Parameter {
126126
}
127127

128128
/**
129-
* A SAL element, i.e. a SAL annotation or a declaration entry
129+
* A SAL element, that is, a SAL annotation or a declaration entry
130130
* that may have SAL annotations.
131131
*/
132132
library class SALElement extends Element {

cpp/ql/src/Security/CWE/CWE-457/InitializationFunctions.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class ParameterNullCheck extends ParameterCheck {
8989
(
9090
va = this.(NotExpr).getOperand() or
9191
va = any(EQExpr eq | eq = this and eq.getAnOperand().getValue() = "0").getAnOperand() or
92-
va = getAssertedFalseCondition(this) or
92+
va = getCheckedFalseCondition(this) or
9393
va = any(NEExpr eq |
94-
eq = getAssertedFalseCondition(this) and eq.getAnOperand().getValue() = "0"
94+
eq = getCheckedFalseCondition(this) and eq.getAnOperand().getValue() = "0"
9595
).getAnOperand()
9696
)
9797
or
@@ -101,7 +101,7 @@ class ParameterNullCheck extends ParameterCheck {
101101
va = this or
102102
va = any(NEExpr eq | eq = this and eq.getAnOperand().getValue() = "0").getAnOperand() or
103103
va = any(EQExpr eq |
104-
eq = getAssertedFalseCondition(this) and eq.getAnOperand().getValue() = "0"
104+
eq = getCheckedFalseCondition(this) and eq.getAnOperand().getValue() = "0"
105105
).getAnOperand()
106106
)
107107
)
@@ -567,7 +567,7 @@ Expr getAnInitializedArgument(Call call) { result = call.getArgument(initialized
567567
* the call, under the given context and evidence.
568568
*/
569569
pragma[nomagic]
570-
int conditionallyInitializedArgument(
570+
private int conditionallyInitializedArgument(
571571
Call call, ConditionalInitializationFunction target, Context c, Evidence e
572572
) {
573573
target = getTarget(call) and
@@ -588,7 +588,7 @@ Expr getAConditionallyInitializedArgument(
588588
/**
589589
* Gets the type signature for the functions parameters.
590590
*/
591-
string typeSig(Function f) {
591+
private string typeSig(Function f) {
592592
result = concat(int i, Type pt |
593593
pt = f.getParameter(i).getType()
594594
|
@@ -599,7 +599,7 @@ string typeSig(Function f) {
599599
/**
600600
* Holds where qualifiedName and typeSig make up the signature for the function.
601601
*/
602-
predicate functionSignature(Function f, string qualifiedName, string typeSig) {
602+
private predicate functionSignature(Function f, string qualifiedName, string typeSig) {
603603
qualifiedName = f.getQualifiedName() and
604604
typeSig = typeSig(f)
605605
}
@@ -611,7 +611,7 @@ predicate functionSignature(Function f, string qualifiedName, string typeSig) {
611611
* This is useful for identifying call to target dependencies across libraries, where the libraries
612612
* are never statically linked together.
613613
*/
614-
Function getAPossibleDefinition(Function undefinedFunction) {
614+
private Function getAPossibleDefinition(Function undefinedFunction) {
615615
not undefinedFunction.isDefined() and
616616
exists(string qn, string typeSig |
617617
functionSignature(undefinedFunction, qn, typeSig) and functionSignature(result, qn, typeSig)
@@ -684,15 +684,15 @@ FieldAccess getAFieldAccess(Variable v) {
684684
}
685685

686686
/**
687-
* Gets a condition which is asserted to be false by the given `ne` expression, according to this pattern:
687+
* Gets a condition which is checked to be false by the given `ne` expression, according to this pattern:
688688
* ```
689689
* int a = !!result;
690690
* if (!a) { // <- ne
691691
* ....
692692
* }
693693
* ```
694694
*/
695-
Expr getAssertedFalseCondition(NotExpr ne) {
695+
private Expr getCheckedFalseCondition(NotExpr ne) {
696696
exists(LocalVariable v |
697697
result = v.getInitializer().getExpr().(NotExpr).getOperand().(NotExpr).getOperand() and
698698
ne.getOperand() = v.getAnAccess() and

cpp/ql/src/semmle/code/cpp/NestedFields.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import cpp
22

33
/**
4-
* Gets a `Field` that is nested within the given `Struct`.
5-
*
6-
* This identifies `Field`s which are located in the same memory
4+
* Gets a `Field` that is within the given `Struct`, either directly or nested
5+
* inside one or more levels of member structs.
76
*/
87
private Field getANestedField(Struct s) {
98
result = s.getAField()
@@ -15,7 +14,7 @@ private Field getANestedField(Struct s) {
1514
}
1615

1716
/**
18-
* Unwraps a series of field accesses to determine the inner-most qualifier.
17+
* Unwraps a series of field accesses to determine the outer-most qualifier.
1918
*/
2019
private Expr getUltimateQualifier(FieldAccess fa) {
2120
exists(Expr qualifier | qualifier = fa.getQualifier() |

cpp/ql/src/semmle/code/cpp/dispatch/VirtualDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module VirtualDispatch {
6767

6868
/**
6969
* Holds if `c` cannot inherit the member function `f`,
70-
* i.e. `c` or one of its supertypes overrides `f`.
70+
* that is, `c` or one of its supertypes overrides `f`.
7171
*/
7272
private predicate cannotInherit(Class c, MemberFunction f) {
7373
exists(Class overridingType, MemberFunction override |

cpp/ql/src/semmle/code/cpp/security/boostorg/asio/protocols.qll

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import semmle.code.cpp.dataflow.DataFlow
33

44
module BoostorgAsio {
55
/**
6-
* Represents boost::asio::ssl::context enum
6+
* Represents the `boost::asio::ssl::context` enum.
77
*/
88
class SslContextMethod extends Enum {
99
SslContextMethod() {
@@ -12,7 +12,7 @@ module BoostorgAsio {
1212
}
1313

1414
/**
15-
* returns the value for a banned protocol
15+
* Gets an enumeration constant for a banned protocol.
1616
*/
1717
EnumConstant getABannedProtocolConstant() {
1818
result = this.getAnEnumConstant() and
@@ -56,14 +56,15 @@ module BoostorgAsio {
5656
}
5757

5858
/**
59-
* returns the value for a approved protocols, but that are hard-coded (i.e. no protocol negotiation)
59+
* Gets an enumeration constant for an approved protocol, that is hard-coded
60+
* (no protocol negotiation).
6061
*/
6162
EnumConstant getAnApprovedButHardcodedProtocolConstant() {
6263
result = this.getATls12ProtocolConstant()
6364
}
6465

6566
/**
66-
* returns the value for a TLS v1.2 protocol
67+
* Gets an enumeration constant for a TLS v1.2 protocol.
6768
*/
6869
EnumConstant getATls12ProtocolConstant() {
6970
result = this.getAnEnumConstant() and
@@ -80,7 +81,7 @@ module BoostorgAsio {
8081
}
8182

8283
/**
83-
* returns the value for a TLS v1.3 protocol
84+
* Gets an enumeration constant for a TLS v1.3 protocol.
8485
*/
8586
EnumConstant getATls13ProtocolConstant() {
8687
result = this.getAnEnumConstant() and
@@ -97,7 +98,7 @@ module BoostorgAsio {
9798
}
9899

99100
/**
100-
* returns the value of a generic TLS or SSL/TLS protocol
101+
* Gets an enumeration constant for a generic TLS or SSL/TLS protocol.
101102
*/
102103
EnumConstant getAGenericTlsProtocolConstant() {
103104
result = this.getAnEnumConstant() and
@@ -116,7 +117,7 @@ module BoostorgAsio {
116117
}
117118

118119
/**
119-
* returns the value of a generic SSL/TLS protocol
120+
* Gets an enumeration constant for a generic SSL/TLS protocol.
120121
*/
121122
EnumConstant getASslv23ProtocolConstant() {
122123
result = this.getAnEnumConstant() and
@@ -135,55 +136,57 @@ module BoostorgAsio {
135136
}
136137

137138
/**
138-
* NOTE: ignore - Modern versions of OpenSSL do not support SSL v2 anymore, so this option is for backwards compatibility only
139+
* Gets the value for the no_sslv2 constant, right shifted by 16 bits.
140+
*
141+
* Note that modern versions of OpelSSL do not support SSL v2, so this option is for backwards compatibility only.
139142
*/
140143
int getShiftedSslOptionsNoSsl2() {
141144
// SSL_OP_NO_SSLv2 was removed from modern OpenSSL versions
142145
result = 0
143146
}
144147

145148
/**
146-
* RightShift(16) value for no_sslv3 constant
149+
* Gets the value for the no_sslv3 constant, right shifted by 16 bits.
147150
*/
148151
int getShiftedSslOptionsNoSsl3() {
149152
// SSL_OP_NO_SSLv3 == 0x02000000U
150153
result = 512
151154
}
152155

153156
/**
154-
* RightShift(16) value for no_tlsv1 constant
157+
* Gets the value for the no_tlsv1 constant, right shifted by 16 bits.
155158
*/
156159
int getShiftedSslOptionsNoTls1() {
157160
// SSL_OP_NO_TLSv1 == 0x04000000U
158161
result = 1024
159162
}
160163

161164
/**
162-
* RightShift(16) value for no_tlsv1_1 constant
165+
* Gets the value for the no_tlsv1_1 constant, right shifted by 16 bits.
163166
*/
164167
int getShiftedSslOptionsNoTls1_1() {
165168
// SSL_OP_NO_TLSv1_1 == 0x10000000U
166169
result = 4096
167170
}
168171

169172
/**
170-
* RightShift(16) value for no_tlsv1_2 constant
173+
* Gets the value for the no_tlsv1_2 constant, right shifted by 16 bits.
171174
*/
172175
int getShiftedSslOptionsNoTls1_2() {
173176
// SSL_OP_NO_TLSv1_2 == 0x08000000U
174177
result = 2048
175178
}
176179

177180
/**
178-
* RightShift(16) value for no_tlsv1_3 constant
181+
* Gets the value for the no_tlsv1_3 constant, right shifted by 16 bits.
179182
*/
180183
int getShiftedSslOptionsNoTls1_3() {
181184
// SSL_OP_NO_TLSv1_2 == 0x20000000U
182185
result = 8192
183186
}
184187

185188
/**
186-
* Represents boost::asio::ssl::context class
189+
* Represents the `boost::asio::ssl::context` class.
187190
*/
188191
class SslContextClass extends Class {
189192
SslContextClass() { this.getQualifiedName() = "boost::asio::ssl::context" }
@@ -196,7 +199,7 @@ module BoostorgAsio {
196199
}
197200

198201
/**
199-
* Represents boost::asio::ssl::context::set_options member function
202+
* Represents `boost::asio::ssl::context::set_options` member function.
200203
*/
201204
class SslSetOptionsFunction extends Function {
202205
SslSetOptionsFunction() {
@@ -205,7 +208,7 @@ module BoostorgAsio {
205208
}
206209

207210
/**
208-
* holds if the expression represents a banned protocol
211+
* Holds if the expression represents a banned protocol.
209212
*/
210213
predicate isExprBannedBoostProtocol(Expr e) {
211214
exists(Literal va | va = e |
@@ -244,7 +247,7 @@ module BoostorgAsio {
244247
}
245248

246249
/**
247-
* holds if the expression represents a TLS v1.2 protocol
250+
* Holds if the expression represents a TLS v1.2 protocol.
248251
*/
249252
predicate isExprTls12BoostProtocol(Expr e) {
250253
exists(Literal va | va = e |
@@ -269,7 +272,7 @@ module BoostorgAsio {
269272
}
270273

271274
/**
272-
* holds if the expression represents a protocol that requires Crypto Board approval
275+
* Holds if the expression represents a protocol that requires Crypto Board approval.
273276
*/
274277
predicate isExprTls13BoostProtocol(Expr e) {
275278
exists(Literal va | va = e |
@@ -294,7 +297,7 @@ module BoostorgAsio {
294297
}
295298

296299
/**
297-
* holds if the expression represents a generic TLS or SSL/TLS protocol
300+
* Holds if the expression represents a generic TLS or SSL/TLS protocol.
298301
*/
299302
predicate isExprTlsBoostProtocol(Expr e) {
300303
exists(Literal va | va = e |
@@ -325,7 +328,7 @@ module BoostorgAsio {
325328
}
326329

327330
/**
328-
* holds if the expression represents a generic SSl/TLS protocol
331+
* Holds if the expression represents a generic SSl/TLS protocol.
329332
*/
330333
predicate isExprSslV23BoostProtocol(Expr e) {
331334
exists(Literal va | va = e |
@@ -351,7 +354,8 @@ module BoostorgAsio {
351354

352355
//////////////////////// Dataflow /////////////////////
353356
/**
354-
* Abstract - Protocol value Flows to the first argument of the context constructor
357+
* Abstract class for flows of protocol values to the first argument of a context
358+
* constructor.
355359
*/
356360
abstract class SslContextCallAbstractConfig extends DataFlow::Configuration {
357361
bindingset[this]
@@ -366,7 +370,7 @@ module BoostorgAsio {
366370
}
367371

368372
/**
369-
* any Protocol value Flows to the first argument of the context constructor
373+
* Any protocol value that flows to the first argument of a context constructor.
370374
*/
371375
class SslContextCallConfig extends SslContextCallAbstractConfig {
372376
SslContextCallConfig() { this = "SslContextCallConfig" }
@@ -380,7 +384,7 @@ module BoostorgAsio {
380384
}
381385

382386
/**
383-
* a banned protocol value Flows to the first argument of the context constructor
387+
* A banned protocol value that flows to the first argument of a context constructor.
384388
*/
385389
class SslContextCallBannedProtocolConfig extends SslContextCallAbstractConfig {
386390
SslContextCallBannedProtocolConfig() { this = "SslContextCallBannedProtocolConfig" }
@@ -395,7 +399,7 @@ module BoostorgAsio {
395399
}
396400

397401
/**
398-
* a TLS 1.2 protocol value Flows to the first argument of the context constructor
402+
* A TLS 1.2 protocol value that flows to the first argument of a context constructor.
399403
*/
400404
class SslContextCallTls12ProtocolConfig extends SslContextCallAbstractConfig {
401405
SslContextCallTls12ProtocolConfig() { this = "SslContextCallTls12ProtocolConfig" }
@@ -410,7 +414,7 @@ module BoostorgAsio {
410414
}
411415

412416
/**
413-
* a TLS 1.3 protocol value Flows to the first argument of the context constructor
417+
* A TLS 1.3 protocol value that flows to the first argument of a context constructor.
414418
*/
415419
class SslContextCallTls13ProtocolConfig extends SslContextCallAbstractConfig {
416420
SslContextCallTls13ProtocolConfig() { this = "SslContextCallTls12ProtocolConfig" }
@@ -425,7 +429,7 @@ module BoostorgAsio {
425429
}
426430

427431
/**
428-
* a generic TLS protocol value Flows to the first argument of the context constructor
432+
* A generic TLS protocol value that flows to the first argument of a context constructor.
429433
*/
430434
class SslContextCallTlsProtocolConfig extends SslContextCallAbstractConfig {
431435
SslContextCallTlsProtocolConfig() { this = "SslContextCallTlsProtocolConfig" }
@@ -440,7 +444,7 @@ module BoostorgAsio {
440444
}
441445

442446
/**
443-
* a context constructor call flows to a call calling SetOptions()
447+
* A context constructor call that flows to a call to `SetOptions()`.
444448
*/
445449
class SslContextFlowsToSetOptionConfig extends DataFlow::Configuration {
446450
SslContextFlowsToSetOptionConfig() { this = "SslContextFlowsToSetOptionConfig" }
@@ -464,7 +468,7 @@ module BoostorgAsio {
464468
}
465469

466470
/**
467-
* an option value flows to the 1st parameter of SetOptions()
471+
* An option value that flows to the first parameter of a call to `SetOptions()`.
468472
*/
469473
class SslOptionConfig extends DataFlow::Configuration {
470474
SslOptionConfig() { this = "SslOptionConfig" }

0 commit comments

Comments
 (0)