Skip to content

Commit 8014bdc

Browse files
committed
C++: Add failing test for 'cpp/tainted-arithmetic'.
1 parent dec4207 commit 8014bdc

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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 | fgets output argument | test2.cpp:39:9:39:11 | num |
12+
| test2.cpp:36:9:36:14 | fgets output argument | test2.cpp:39:9:39:11 | num |
713
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:17:6:17:18 | call to getTaintedInt |
814
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:17:6:17:18 | call to getTaintedInt |
915
| test5.cpp:5:5:5:17 | getTaintedInt indirection | test5.cpp:18:6:18:18 | call to getTaintedInt |
@@ -32,6 +38,11 @@ nodes
3238
| test2.cpp:25:22:25:23 | & ... | semmle.label | & ... |
3339
| test2.cpp:25:22:25:23 | fscanf output argument | semmle.label | fscanf output argument |
3440
| test2.cpp:27:13:27:13 | v | semmle.label | v |
41+
| test2.cpp:36:9:36:14 | buffer | semmle.label | buffer |
42+
| test2.cpp:36:9:36:14 | buffer | semmle.label | buffer |
43+
| test2.cpp:36:9:36:14 | fgets output argument | semmle.label | fgets output argument |
44+
| test2.cpp:39:9:39:11 | num | semmle.label | num |
45+
| test2.cpp:39:9:39:11 | num | semmle.label | num |
3546
| test5.cpp:5:5:5:17 | getTaintedInt indirection | semmle.label | getTaintedInt indirection |
3647
| test5.cpp:9:7:9:9 | buf | semmle.label | buf |
3748
| test5.cpp:9:7:9:9 | buf | semmle.label | buf |
@@ -56,6 +67,7 @@ nodes
5667
#select
5768
| 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 |
5869
| 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 |
70+
| 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 |
5971
| 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 |
6072
| 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 |
6173
| 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 [NOT DETECTED]
41+
}

0 commit comments

Comments
 (0)