|
13 | 13 | import cpp
|
14 | 14 | import semmle.code.cpp.ir.dataflow.DataFlow
|
15 | 15 | import semmle.code.cpp.ir.IR
|
| 16 | +import DataFlow::PathGraph |
16 | 17 |
|
17 | 18 | // Gets the recommended minimum key size (in bits) of `func`, the name of an encryption function that accepts a key size as parameter `paramIndex`
|
18 | 19 | int getMinimumKeyStrength(string func, int paramIndex) {
|
@@ -43,14 +44,16 @@ class KeyStrengthFlow extends DataFlow::Configuration {
|
43 | 44 | }
|
44 | 45 |
|
45 | 46 | from
|
46 |
| - DataFlow::PathNode source, DataFlow::PathNode sink, KeyStrengthFlow conf, FunctionCall fc, int param, |
47 |
| - string name, int bits |
| 47 | + DataFlow::PathNode source, DataFlow::PathNode sink, KeyStrengthFlow conf, FunctionCall fc, |
| 48 | + int param, string name, int minimumBits, int bits |
48 | 49 | where
|
49 | 50 | conf.hasFlowPath(source, sink) and
|
50 | 51 | sink.getNode().asExpr() = fc.getArgument(param) and
|
51 | 52 | fc.getTarget().hasGlobalName(name) and
|
52 |
| - bits = getMinimumKeyStrength(name, param) and |
53 |
| - source.getNode().asInstruction().(ConstantValueInstruction).getValue().toInt() < bits |
| 53 | + minimumBits = getMinimumKeyStrength(name, param) and |
| 54 | + bits = source.getNode().asInstruction().(ConstantValueInstruction).getValue().toInt() and |
| 55 | + bits < minimumBits and |
| 56 | + bits != 0 |
54 | 57 | select fc, source, sink,
|
55 |
| - "The key size $@ is less than the recommended key size of " + bits.toString() + " bits.", source, |
56 |
| - source.toString() |
| 58 | + "The key size $@ is less than the recommended key size of " + minimumBits.toString() + " bits.", |
| 59 | + source, bits.toString() |
0 commit comments