|
12 | 12 | import cpp |
13 | 13 | import semmle.code.cpp.security.boostorg.asio.protocols |
14 | 14 |
|
| 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 | + |
15 | 26 | 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, _) } |
19 | 28 |
|
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, _) } |
26 | 30 | } |
27 | 31 |
|
28 | 32 | module ExistsAnyFlow = DataFlow::Global<ExistsAnyFlowConfig>; |
29 | 33 |
|
30 | 34 | bindingset[flag] |
31 | 35 | 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 |
43 | 51 | ) |
44 | 52 | ) |
45 | 53 | } |
|
0 commit comments