Skip to content

Commit a37f746

Browse files
committed
C++: fix FP and add paths in InsufficientKeySize
1 parent 103796d commit a37f746

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

cpp/ql/src/Security/CWE/CWE-326/InsufficientKeySize.ql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import cpp
1414
import semmle.code.cpp.ir.dataflow.DataFlow
1515
import semmle.code.cpp.ir.IR
16+
import DataFlow::PathGraph
1617

1718
// Gets the recommended minimum key size (in bits) of `func`, the name of an encryption function that accepts a key size as parameter `paramIndex`
1819
int getMinimumKeyStrength(string func, int paramIndex) {
@@ -43,14 +44,16 @@ class KeyStrengthFlow extends DataFlow::Configuration {
4344
}
4445

4546
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
4849
where
4950
conf.hasFlowPath(source, sink) and
5051
sink.getNode().asExpr() = fc.getArgument(param) and
5152
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
5457
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()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
edges
2+
nodes
3+
| test.cpp:28:45:28:48 | 2048 | semmle.label | 2048 |
4+
| test.cpp:29:49:29:52 | 2048 | semmle.label | 2048 |
5+
| test.cpp:31:43:31:46 | 2048 | semmle.label | 2048 |
6+
| test.cpp:34:45:34:48 | 1024 | semmle.label | 1024 |
7+
| test.cpp:35:49:35:52 | 1024 | semmle.label | 1024 |
8+
| test.cpp:37:43:37:46 | 1024 | semmle.label | 1024 |
9+
subpaths
10+
#select
111
| test.cpp:34:5:34:38 | call to EVP_PKEY_CTX_set_dsa_paramgen_bits | test.cpp:34:45:34:48 | 1024 | test.cpp:34:45:34:48 | 1024 | The key size $@ is less than the recommended key size of 2048 bits. | test.cpp:34:45:34:48 | 1024 | 1024 |
212
| test.cpp:35:5:35:42 | call to EVP_PKEY_CTX_set_dh_paramgen_prime_len | test.cpp:35:49:35:52 | 1024 | test.cpp:35:49:35:52 | 1024 | The key size $@ is less than the recommended key size of 2048 bits. | test.cpp:35:49:35:52 | 1024 | 1024 |
313
| test.cpp:37:5:37:36 | call to EVP_PKEY_CTX_set_rsa_keygen_bits | test.cpp:37:43:37:46 | 1024 | test.cpp:37:43:37:46 | 1024 | The key size $@ is less than the recommended key size of 2048 bits. | test.cpp:37:43:37:46 | 1024 | 1024 |

0 commit comments

Comments
 (0)