Skip to content

Commit 1330c88

Browse files
committed
C++: Use 'asIndirectExpr' in the sink of 'ExistsAnyFlowConfig.
1 parent e3be205 commit 1330c88

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

cpp/ql/src/Likely Bugs/Protocols/TlsSettingsMisconfiguration.ql

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,42 @@
1212
import cpp
1313
import semmle.code.cpp.security.boostorg.asio.protocols
1414

15+
predicate isSourceImpl(DataFlow::Node source, ConstructorCall cc) {
16+
exists(BoostorgAsio::SslContextClass c | c.getAContructorCall() = cc and cc = source.asExpr())
17+
}
18+
19+
predicate isSinkImpl(DataFlow::Node sink, FunctionCall fcSetOptions) {
20+
exists(BoostorgAsio::SslSetOptionsFunction f |
21+
f.getACallToThisFunction() = fcSetOptions and
22+
fcSetOptions.getQualifier() = sink.asIndirectExpr()
23+
)
24+
}
25+
1526
module ExistsAnyFlowConfig implements DataFlow::ConfigSig {
16-
predicate isSource(DataFlow::Node source) {
17-
exists(BoostorgAsio::SslContextClass c | c.getAContructorCall() = source.asExpr())
18-
}
27+
predicate isSource(DataFlow::Node source) { isSourceImpl(source, _) }
1928

20-
predicate isSink(DataFlow::Node sink) {
21-
exists(BoostorgAsio::SslSetOptionsFunction f, FunctionCall fcSetOptions |
22-
f.getACallToThisFunction() = fcSetOptions and
23-
fcSetOptions.getQualifier() = sink.asExpr()
24-
)
25-
}
29+
predicate isSink(DataFlow::Node sink) { isSinkImpl(sink, _) }
2630
}
2731

2832
module ExistsAnyFlow = DataFlow::Global<ExistsAnyFlowConfig>;
2933

3034
bindingset[flag]
3135
predicate isOptionSet(ConstructorCall cc, int flag, FunctionCall fcSetOptions) {
32-
exists(VariableAccess contextSetOptions |
33-
ExistsAnyFlow::flow(DataFlow::exprNode(cc), DataFlow::exprNode(contextSetOptions)) and
34-
exists(BoostorgAsio::SslSetOptionsFunction f | f.getACallToThisFunction() = fcSetOptions |
35-
contextSetOptions = fcSetOptions.getQualifier() and
36-
forall(Expr optionArgument, Expr optionArgumentSource |
37-
optionArgument = fcSetOptions.getArgument(0) and
38-
BoostorgAsio::SslOptionFlow::flow(DataFlow::exprNode(optionArgumentSource),
39-
DataFlow::exprNode(optionArgument))
40-
|
41-
optionArgument.getValue().toInt().bitShiftRight(16).bitAnd(flag) = flag
42-
)
36+
exists(
37+
VariableAccess contextSetOptions, BoostorgAsio::SslSetOptionsFunction f, DataFlow::Node source,
38+
DataFlow::Node sink
39+
|
40+
isSourceImpl(source, cc) and
41+
isSinkImpl(sink, fcSetOptions) and
42+
ExistsAnyFlow::flow(source, sink) and
43+
f.getACallToThisFunction() = fcSetOptions and
44+
contextSetOptions = fcSetOptions.getQualifier() and
45+
forall(Expr optionArgument, Expr optionArgumentSource |
46+
optionArgument = fcSetOptions.getArgument(0) and
47+
BoostorgAsio::SslOptionFlow::flow(DataFlow::exprNode(optionArgumentSource),
48+
DataFlow::exprNode(optionArgument))
49+
|
50+
optionArgument.getValue().toInt().bitShiftRight(16).bitAnd(flag) = flag
4351
)
4452
)
4553
}

0 commit comments

Comments
 (0)