Skip to content

Commit 40f0658

Browse files
committed
C++: Exclude unintended results on pointers.
1 parent 503c5c9 commit 40f0658

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

cpp/ql/src/Security/CWE/CWE-190/ArithmeticUncontrolled.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class UncontrolledArithConfiguration extends TaintTracking::Configuration {
108108
op instanceof BitwiseAndExpr or
109109
op instanceof ComplementExpr
110110
).getAnOperand*()
111+
or
112+
// block unintended flow to pointers
113+
node.asExpr().getUnspecifiedType() instanceof PointerType
111114
}
112115
}
113116

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/uncontrolled/ArithmeticUncontrolled.expected

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ edges
2020
| test.cpp:36:13:36:13 | Chi | test.cpp:37:7:37:7 | r |
2121
| test.cpp:36:13:36:13 | get_rand3 output argument [[]] | test.cpp:36:13:36:13 | Chi |
2222
| test.cpp:54:10:54:13 | call to rand | test.cpp:57:9:57:9 | x |
23-
| test.cpp:63:23:63:31 | buf_start | test.cpp:67:9:67:11 | len |
24-
| test.cpp:63:40:63:46 | buf_end | test.cpp:67:9:67:11 | len |
25-
| test.cpp:72:50:72:53 | call to rand | test.cpp:73:2:73:12 | ... + ... |
26-
| test.cpp:72:50:72:53 | call to rand | test.cpp:73:2:73:12 | buf |
27-
| test.cpp:73:2:73:12 | ... + ... | test.cpp:63:40:63:46 | buf_end |
28-
| test.cpp:73:2:73:12 | buf | test.cpp:63:23:63:31 | buf_start |
2923
| test.cpp:78:10:78:13 | call to rand | test.cpp:82:10:82:10 | x |
3024
| test.cpp:78:10:78:13 | call to rand | test.cpp:84:10:84:10 | x |
3125
| test.cpp:90:10:90:13 | call to rand | test.cpp:94:10:94:10 | x |
@@ -65,12 +59,6 @@ nodes
6559
| test.cpp:37:7:37:7 | r | semmle.label | r |
6660
| test.cpp:54:10:54:13 | call to rand | semmle.label | call to rand |
6761
| test.cpp:57:9:57:9 | x | semmle.label | x |
68-
| test.cpp:63:23:63:31 | buf_start | semmle.label | buf_start |
69-
| test.cpp:63:40:63:46 | buf_end | semmle.label | buf_end |
70-
| test.cpp:67:9:67:11 | len | semmle.label | len |
71-
| test.cpp:72:50:72:53 | call to rand | semmle.label | call to rand |
72-
| test.cpp:73:2:73:12 | ... + ... | semmle.label | ... + ... |
73-
| test.cpp:73:2:73:12 | buf | semmle.label | buf |
7462
| test.cpp:78:10:78:13 | call to rand | semmle.label | call to rand |
7563
| test.cpp:82:10:82:10 | x | semmle.label | x |
7664
| test.cpp:84:10:84:10 | x | semmle.label | x |
@@ -96,8 +84,6 @@ nodes
9684
| test.cpp:31:7:31:7 | r | test.cpp:13:10:13:13 | call to rand | test.cpp:31:7:31:7 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:13:10:13:13 | call to rand | Uncontrolled value |
9785
| test.cpp:37:7:37:7 | r | test.cpp:18:9:18:12 | call to rand | test.cpp:37:7:37:7 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:18:9:18:12 | call to rand | Uncontrolled value |
9886
| test.cpp:57:9:57:9 | x | test.cpp:54:10:54:13 | call to rand | test.cpp:57:9:57:9 | x | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.cpp:54:10:54:13 | call to rand | Uncontrolled value |
99-
| test.cpp:67:9:67:11 | len | test.cpp:72:50:72:53 | call to rand | test.cpp:67:9:67:11 | len | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:72:50:72:53 | call to rand | Uncontrolled value |
100-
| test.cpp:67:9:67:11 | len | test.cpp:72:50:72:53 | call to rand | test.cpp:67:9:67:11 | len | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.cpp:72:50:72:53 | call to rand | Uncontrolled value |
10187
| test.cpp:82:10:82:10 | x | test.cpp:78:10:78:13 | call to rand | test.cpp:82:10:82:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:78:10:78:13 | call to rand | Uncontrolled value |
10288
| test.cpp:84:10:84:10 | x | test.cpp:78:10:78:13 | call to rand | test.cpp:84:10:84:10 | x | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.cpp:78:10:78:13 | call to rand | Uncontrolled value |
10389
| test.cpp:94:10:94:10 | x | test.cpp:90:10:90:13 | call to rand | test.cpp:94:10:94:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:90:10:90:13 | call to rand | Uncontrolled value |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/uncontrolled/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int test_buffer(char *buf_start, char *buf_end)
6464
{
6565
int len = buf_end - buf_start;
6666

67-
return len * 2; // GOOD [FALSE POSITIVE]
67+
return len * 2; // GOOD
6868
}
6969

7070
int test_snprintf(char *buf, size_t buf_sz)

0 commit comments

Comments
 (0)