Skip to content

Commit 6ca9c44

Browse files
committed
C++: Add a test demonstrating the recent regression.
1 parent 22097a9 commit 6ca9c44

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| test2.cpp:14:11:14:11 | v | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
2+
| test2.cpp:14:11:14:11 | v | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
13
| 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 |
24
| 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 |
35
| 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 |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
| test2.cpp:14:11:14:15 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
2+
| test2.cpp:16:11:16:21 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
3+
| test2.cpp:17:11:17:22 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value |
14
| test3.c:12:31:12:34 | * ... | $@ flows to here and is used in an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value |
25
| test3.c:13:16:13:19 | * ... | $@ flows to here and is used in an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value |
36
| test4.cpp:13:17:13:20 | access to array | $@ flows to here and is used in an expression which might overflow negatively. | test4.cpp:9:13:9:16 | argv | User-provided value |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
typedef signed long long int s64;
3+
4+
typedef struct {} FILE;
5+
int fscanf(FILE *stream, const char *format, ...);
6+
FILE *stdin;
7+
8+
typedef struct _myStruct {
9+
s64 val;
10+
} MyStruct;
11+
12+
void test2_sink(s64 v, MyStruct s, MyStruct &s_r, MyStruct *s_p)
13+
{
14+
s64 v1 = v * 2; // bad
15+
s64 v2 = s.val * 2; // bad [NOT DETECTED]
16+
s64 v3 = s_r.val * 2; // bad
17+
s64 v4 = s_p->val * 2; // bad
18+
}
19+
20+
void test2_source()
21+
{
22+
MyStruct ms;
23+
s64 v;
24+
25+
fscanf(stdin, "%i", &v);
26+
ms.val = v;
27+
test2_sink(v, ms, ms, &ms);
28+
}

0 commit comments

Comments
 (0)