Skip to content

Commit a48d5dc

Browse files
authored
Merge pull request #7459 from MathiasVP/promote-arithmetic-uncontrolled
C++: Increase precision of `cpp/arithmetic-uncontrolled` to `high`
2 parents fdb3cd0 + 23b8b77 commit a48d5dc

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @kind path-problem
66
* @problem.severity warning
77
* @security-severity 8.6
8-
* @precision medium
8+
* @precision high
99
* @id cpp/uncontrolled-arithmetic
1010
* @tags security
1111
* external/cwe/cwe-190
@@ -82,8 +82,11 @@ predicate missingGuard(VariableAccess va, string effect) {
8282
op.getUnspecifiedType().(IntegralType).isUnsigned() and
8383
not op instanceof MulExpr
8484
or
85-
// overflow
86-
missingGuardAgainstOverflow(op, va) and effect = "overflow"
85+
// overflow - only report signed integer overflow since unsigned overflow
86+
// is well-defined.
87+
op.getUnspecifiedType().(IntegralType).isSigned() and
88+
missingGuardAgainstOverflow(op, va) and
89+
effect = "overflow"
8790
)
8891
}
8992

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* The "Uncontrolled data in arithmetic expression" (cpp/uncontrolled-arithmetic) query has been enhanced to reduce false positive results and its @precision increased to high.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ edges
3535
| test.cpp:190:10:190:13 | call to rand | test.cpp:205:7:205:7 | y |
3636
| test.cpp:190:10:190:13 | call to rand | test.cpp:208:7:208:7 | y |
3737
| test.cpp:215:11:215:14 | call to rand | test.cpp:219:8:219:8 | x |
38-
| test.cpp:223:20:223:23 | call to rand | test.cpp:227:8:227:8 | x |
39-
| test.cpp:223:20:223:25 | (unsigned int)... | test.cpp:227:8:227:8 | x |
4038
nodes
4139
| test.c:18:13:18:16 | call to rand | semmle.label | call to rand |
4240
| test.c:21:17:21:17 | r | semmle.label | r |
@@ -92,9 +90,6 @@ nodes
9290
| test.cpp:208:7:208:7 | y | semmle.label | y |
9391
| test.cpp:215:11:215:14 | call to rand | semmle.label | call to rand |
9492
| test.cpp:219:8:219:8 | x | semmle.label | x |
95-
| test.cpp:223:20:223:23 | call to rand | semmle.label | call to rand |
96-
| test.cpp:223:20:223:25 | (unsigned int)... | semmle.label | (unsigned int)... |
97-
| test.cpp:227:8:227:8 | x | semmle.label | x |
9893
subpaths
9994
#select
10095
| test.c:21:17:21:17 | r | test.c:18:13:18:16 | call to rand | test.c:21:17:21:17 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:18:13:18:16 | call to rand | Uncontrolled value |
@@ -125,5 +120,3 @@ subpaths
125120
| test.cpp:205:7:205:7 | y | test.cpp:190:10:190:13 | call to rand | test.cpp:205:7:205:7 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:190:10:190:13 | call to rand | Uncontrolled value |
126121
| test.cpp:208:7:208:7 | y | test.cpp:190:10:190:13 | call to rand | test.cpp:208:7:208:7 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:190:10:190:13 | call to rand | Uncontrolled value |
127122
| test.cpp:219:8:219:8 | x | test.cpp:215:11:215:14 | call to rand | test.cpp:219:8:219:8 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:215:11:215:14 | call to rand | Uncontrolled value |
128-
| test.cpp:227:8:227:8 | x | test.cpp:223:20:223:23 | call to rand | test.cpp:227:8:227:8 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:223:20:223:23 | call to rand | Uncontrolled value |
129-
| test.cpp:227:8:227:8 | x | test.cpp:223:20:223:25 | (unsigned int)... | test.cpp:227:8:227:8 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:223:20:223:23 | call to rand | Uncontrolled value |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,6 @@ void test_mod_limit()
224224
unsigned int y = 100;
225225
unsigned int z;
226226

227-
z = (x + y) % 1000; // DUBIOUS (this could overflow but the result is controlled) [REPORTED]
227+
z = (x + y) % 1000; // DUBIOUS (this could overflow but the result is controlled)
228228
}
229229
}

0 commit comments

Comments
 (0)