Skip to content

Commit d6b53ab

Browse files
authored
Merge pull request github#12779 from MathiasVP/fix-missing-result-in-arith-tainted
C++: Fix FN in `cpp/tainted-arithmetic`
2 parents e2f64de + 025081e commit d6b53ab

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class Configuration extends TaintTrackingConfiguration {
3535
op.getAnOperand() = e
3636
|
3737
op instanceof UnaryArithmeticOperation or
38-
op instanceof BinaryArithmeticOperation
38+
op instanceof BinaryArithmeticOperation or
39+
op instanceof AssignArithmeticOperation
3940
)
4041
}
4142

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `cpp/tainted-arithmetic` now also flags possible overflows in arithmetic assignment operations.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ edges
44
| test2.cpp:25:22:25:23 | & ... | test2.cpp:27:13:27:13 | v |
55
| test2.cpp:25:22:25:23 | fscanf output argument | test2.cpp:27:13:27:13 | v |
66
| test2.cpp:27:13:27:13 | v | test2.cpp:12:21:12:21 | v |
7+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:39:9:39:11 | num |
8+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:39:9:39:11 | num |
9+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:39:9:39:11 | num |
10+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:39:9:39:11 | num |
11+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:40:3:40:5 | num |
12+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:40:3:40:5 | num |
13+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:40:3:40:5 | num |
14+
| test2.cpp:36:9:36:14 | buffer | test2.cpp:40:3:40:5 | num |
15+
| test2.cpp:36:9:36:14 | fgets output argument | test2.cpp:39:9:39:11 | num |
16+
| test2.cpp:36:9:36:14 | fgets output argument | test2.cpp:39:9:39:11 | num |
17+
| test2.cpp:36:9:36:14 | fgets output argument | test2.cpp:40:3:40:5 | num |
18+
| test2.cpp:36:9:36:14 | fgets output argument | test2.cpp:40:3:40:5 | num |
719
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:17:6:17:18 | call to getTaintedInt |
820
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:17:6:17:18 | call to getTaintedInt |
921
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:18:6:18:18 | call to getTaintedInt |
@@ -32,6 +44,13 @@ nodes
3244
| test2.cpp:25:22:25:23 | & ... | semmle.label | & ... |
3345
| test2.cpp:25:22:25:23 | fscanf output argument | semmle.label | fscanf output argument |
3446
| test2.cpp:27:13:27:13 | v | semmle.label | v |
47+
| test2.cpp:36:9:36:14 | buffer | semmle.label | buffer |
48+
| test2.cpp:36:9:36:14 | buffer | semmle.label | buffer |
49+
| test2.cpp:36:9:36:14 | fgets output argument | semmle.label | fgets output argument |
50+
| test2.cpp:39:9:39:11 | num | semmle.label | num |
51+
| test2.cpp:39:9:39:11 | num | semmle.label | num |
52+
| test2.cpp:40:3:40:5 | num | semmle.label | num |
53+
| test2.cpp:40:3:40:5 | num | semmle.label | num |
3554
| test5.cpp:5:5:5:17 | getTaintedInt indirection | semmle.label | getTaintedInt indirection |
3655
| test5.cpp:9:7:9:9 | buf | semmle.label | buf |
3756
| test5.cpp:9:7:9:9 | buf | semmle.label | buf |
@@ -56,6 +75,8 @@ nodes
5675
#select
5776
| test2.cpp:14:11:14:11 | v | test2.cpp:25:22:25:23 | & ... | test2.cpp:14:11:14:11 | v | $@ flows to an operand of an arithmetic expression, potentially causing an overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
5877
| test2.cpp:14:11:14:11 | v | test2.cpp:25:22:25:23 | & ... | test2.cpp:14:11:14:11 | v | $@ flows to an operand of an arithmetic expression, potentially causing an underflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
78+
| test2.cpp:39:9:39:11 | num | test2.cpp:36:9:36:14 | buffer | test2.cpp:39:9:39:11 | num | $@ flows to an operand of an arithmetic expression, potentially causing an overflow. | test2.cpp:36:9:36:14 | buffer | User-provided value |
79+
| test2.cpp:40:3:40:5 | num | test2.cpp:36:9:36:14 | buffer | test2.cpp:40:3:40:5 | num | $@ flows to an operand of an arithmetic expression, potentially causing an overflow. | test2.cpp:36:9:36:14 | buffer | User-provided value |
5980
| test5.cpp:17:6:17:18 | call to getTaintedInt | test5.cpp:9:7:9:9 | buf | test5.cpp:17:6:17:18 | call to getTaintedInt | $@ flows to an operand of an arithmetic expression, potentially causing an overflow. | test5.cpp:9:7:9:9 | buf | User-provided value |
6081
| test5.cpp:19:6:19:6 | y | test5.cpp:9:7:9:9 | buf | test5.cpp:19:6:19:6 | y | $@ flows to an operand of an arithmetic expression, potentially causing an overflow. | test5.cpp:9:7:9:9 | buf | User-provided value |
6182
| test5.cpp:19:6:19:6 | y | test5.cpp:9:7:9:9 | buf | test5.cpp:19:6:19:6 | y | $@ flows to an operand of an arithmetic expression, potentially causing an underflow. | test5.cpp:9:7:9:9 | buf | User-provided value |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
| test2.cpp:15:11:15:19 | ... * ... | $@ flows an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
33
| test2.cpp:16:11:16:21 | ... * ... | $@ flows an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
44
| test2.cpp:17:11:17:22 | ... * ... | $@ flows an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
5+
| test2.cpp:39:9:39:18 | ... + ... | $@ flows an expression which might overflow. | test2.cpp:36:9:36:14 | buffer | User-provided value |
6+
| test2.cpp:40:3:40:13 | ... += ... | $@ flows an expression which might overflow. | test2.cpp:36:9:36:14 | buffer | User-provided value |
57
| test3.c:12:31:12:34 | * ... | $@ flows an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value |
68
| test3.c:13:16:13:19 | * ... | $@ flows an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value |
79
| test4.cpp:13:17:13:20 | access to array | $@ flows an expression which might overflow negatively. | test4.cpp:9:13:9:16 | argv | User-provided value |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ void test2_source()
2626
ms.val = v;
2727
test2_sink(v, ms, ms, &ms);
2828
}
29+
30+
char *fgets(char *, int, FILE *);
31+
int atoi(const char *);
32+
33+
void test3()
34+
{
35+
char buffer[20];
36+
fgets(buffer, 20, stdin);
37+
38+
int num = atoi(buffer);
39+
num = num + 1000; // BAD
40+
num += 1000; // BAD
41+
}

0 commit comments

Comments
 (0)