Skip to content

Commit dc5ee7c

Browse files
authored
Merge pull request #16007 from MathiasVP/fix-tls-settings-misconfiguration
C++: Fix `cpp/boost/tls-settings-misconfiguration` FPs
2 parents 7fb6426 + 0ef8c7d commit dc5ee7c

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
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
}

cpp/ql/test/query-tests/Likely Bugs/Protocols/TlsSettingsMisconfiguration.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
| test2.cpp:31:32:31:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:31:32:31:64 | sslv23 | sslv23 | test2.cpp:31:32:31:65 | call to context | no_sslv3 has not been set |
66
| test2.cpp:31:32:31:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:31:32:31:64 | sslv23 | sslv23 | test2.cpp:31:32:31:65 | call to context | no_tlsv1 has not been set |
77
| test2.cpp:31:32:31:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:31:32:31:64 | sslv23 | sslv23 | test2.cpp:31:32:31:65 | call to context | no_tlsv1_1 has not been set |
8-
| test2.cpp:38:35:38:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:38:65:38:97 | sslv23 | sslv23 | test2.cpp:38:35:38:98 | call to context | no_sslv3 has not been set |
9-
| test2.cpp:38:35:38:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:38:65:38:97 | sslv23 | sslv23 | test2.cpp:38:35:38:98 | call to context | no_tlsv1 has not been set |
10-
| test2.cpp:38:35:38:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:38:65:38:97 | sslv23 | sslv23 | test2.cpp:38:35:38:98 | call to context | no_tlsv1_1 has not been set |
118
| test2.cpp:45:35:45:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:45:65:45:97 | sslv23 | sslv23 | test2.cpp:45:35:45:98 | call to context | no_sslv3 has not been set |
12-
| test2.cpp:45:35:45:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:45:65:45:97 | sslv23 | sslv23 | test2.cpp:45:35:45:98 | call to context | no_tlsv1 has not been set |
13-
| test2.cpp:45:35:45:98 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:45:65:45:97 | sslv23 | sslv23 | test2.cpp:45:35:45:98 | call to context | no_tlsv1_1 has not been set |
149
| test2.cpp:52:32:52:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:52:32:52:64 | sslv23 | sslv23 | test2.cpp:52:32:52:65 | call to context | no_sslv3 has not been set |
1510
| test2.cpp:52:32:52:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:52:32:52:64 | sslv23 | sslv23 | test2.cpp:52:32:52:65 | call to context | no_tlsv1 has not been set |
1611
| test2.cpp:52:32:52:65 | call to context | This usage of 'boost::asio::ssl::context::context' with protocol $@ is not configured correctly: The option $@. | test2.cpp:52:32:52:64 | sslv23 | sslv23 | test2.cpp:52:32:52:65 | call to context | no_tlsv1_1 has not been set |

cpp/ql/test/query-tests/Likely Bugs/Protocols/test2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void bad2()
3434

3535
void good3()
3636
{
37-
// GOOD [FALSE POSITIVE]
37+
// GOOD
3838
boost::asio::ssl::context *ctx = new boost::asio::ssl::context(boost::asio::ssl::context::sslv23);
3939
ctx->set_options(boost::asio::ssl::context::no_tlsv1 | boost::asio::ssl::context::no_tlsv1_1 | boost::asio::ssl::context::no_sslv3);
4040
}

0 commit comments

Comments
 (0)