Skip to content

Commit b0805f8

Browse files
committed
CPP: Adjust ArithmeticTainted.ql so that it can work on non-VariableAccesses.
1 parent f1dc538 commit b0805f8

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import semmle.code.cpp.security.Overflow
1616
import semmle.code.cpp.security.Security
1717
import semmle.code.cpp.security.TaintTracking
1818

19-
predicate taintedVarAccess(Expr origin, VariableAccess va) {
20-
isUserInput(origin, _) and
21-
tainted(origin, va)
22-
}
23-
24-
from Expr origin, Operation op, VariableAccess va, string effect
25-
where taintedVarAccess(origin, va)
26-
and op.getAnOperand() = va
19+
from Expr origin, Operation op, Expr e, string effect
20+
where isUserInput(origin, _)
21+
and tainted(origin, e)
22+
and op.getAnOperand() = e
2723
and
2824
(
29-
(missingGuardAgainstUnderflow(op, va) and effect = "underflow") or
30-
(missingGuardAgainstOverflow(op, va) and effect = "overflow")
25+
(missingGuardAgainstUnderflow(op, e) and effect = "underflow") or
26+
(missingGuardAgainstOverflow(op, e) and effect = "overflow") or
27+
(not e instanceof VariableAccess and effect = "overflow")
28+
) and (
29+
op instanceof UnaryArithmeticOperation or
30+
op instanceof BinaryArithmeticOperation
3131
)
32-
select va, "$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".",
32+
select e, "$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".",
3333
origin, "User-provided value"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| test3.c:15:10:15:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test3.c:11:15:11:18 | argv | User-provided value |
22
| test3.c:15:14:15:14 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test3.c:11:15:11:18 | argv | User-provided value |
33
| test3.c:15:18:15:18 | z | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test3.c:11:15:11:18 | argv | User-provided value |
4+
| test5.cpp:17:6:17:18 | call to getTaintedInt | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test5.cpp:9:7:9:9 | buf | User-provided value |
45
| test5.cpp:19:6:19:6 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test5.cpp:9:7:9:9 | buf | User-provided value |
56
| test5.cpp:19:6:19:6 | y | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test5.cpp:9:7:9:9 | buf | User-provided value |
67
| test.c:14:15:14:28 | maxConnections | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:11:29:11:32 | argv | User-provided value |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void useTaintedInt()
1414
{
1515
int x, y;
1616

17-
x = getTaintedInt() * 1024; // BAD: arithmetic on a tainted value [NOT DETECTED]
17+
x = getTaintedInt() * 1024; // BAD: arithmetic on a tainted value
1818
y = getTaintedInt();
1919
y = y * 1024; // BAD: arithmetic on a tainted value
2020
}

0 commit comments

Comments
 (0)