Skip to content

Commit f0f7e53

Browse files
authored
Merge pull request github#3511 from jbj/simplify-field-conflation-test
C++: Simplify field conflation test
2 parents bfeaecc + 486f06a commit f0f7e53

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/defaulttainttracking.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,21 @@ void test_outparams() {
9999
}
100100

101101

102-
void *memcpy(void *dst, void *src, int size);
103102

104-
struct ContainsArray {
105-
int arr[16];
103+
104+
struct XY {
106105
int x;
106+
int y;
107107
};
108108

109-
void taint_array(ContainsArray *ca, int offset) {
109+
void taint_y(XY *xyp) {
110110
int tainted = getenv("VAR")[0];
111-
memcpy(ca->arr + offset, &tainted, sizeof(int));
111+
xyp->y = tainted;
112112
}
113113

114-
void test_conflated_fields3(int arbitrary) {
115-
ContainsArray ca;
116-
ca.x = 0;
117-
taint_array(&ca, arbitrary);
118-
sink(ca.x); // not tainted [FALSE POSITIVE]
114+
void test_conflated_fields3() {
115+
XY xy;
116+
xy.x = 0;
117+
taint_y(&xy);
118+
sink(xy.x); // not tainted [FALSE POSITIVE]
119119
}

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/tainted.expected

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,11 @@
110110
| defaulttainttracking.cpp:97:27:97:32 | call to getenv | defaulttainttracking.cpp:98:10:98:11 | p2 |
111111
| defaulttainttracking.cpp:97:27:97:32 | call to getenv | test_diff.cpp:1:11:1:20 | p#0 |
112112
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:10:11:10:13 | p#0 |
113-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:102:31:102:33 | src |
114113
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:110:7:110:13 | tainted |
115114
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:110:17:110:22 | call to getenv |
116115
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:110:17:110:32 | (int)... |
117116
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:110:17:110:32 | access to array |
118-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:3:111:8 | call to memcpy |
119-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:28:111:35 | & ... |
120-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:28:111:35 | (void *)... |
117+
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:12:111:18 | tainted |
121118
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:118:11:118:11 | x |
122119
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | test_diff.cpp:2:11:2:13 | p#0 |
123120
| globals.cpp:5:20:5:25 | call to getenv | globals.cpp:2:17:2:25 | sinkParam |

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/test_diff.expected

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
| defaulttainttracking.cpp:97:27:97:32 | call to getenv | defaulttainttracking.cpp:98:10:98:11 | p2 | IR only |
2525
| defaulttainttracking.cpp:97:27:97:32 | call to getenv | test_diff.cpp:1:11:1:20 | p#0 | IR only |
2626
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:10:11:10:13 | p#0 | IR only |
27-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:102:20:102:22 | dst | AST only |
28-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:10:111:25 | ... + ... | AST only |
29-
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:29:111:35 | tainted | AST only |
27+
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:111:8:111:8 | y | AST only |
3028
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | defaulttainttracking.cpp:118:11:118:11 | x | IR only |
3129
| defaulttainttracking.cpp:110:17:110:22 | call to getenv | test_diff.cpp:2:11:2:13 | p#0 | IR only |
3230
| globals.cpp:13:15:13:20 | call to getenv | globals.cpp:13:5:13:11 | global1 | AST only |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
edges
2-
| field_conflation.c:12:22:12:27 | call to getenv | field_conflation.c:13:10:13:25 | Chi |
3-
| field_conflation.c:12:22:12:34 | (const char *)... | field_conflation.c:13:10:13:25 | Chi |
4-
| field_conflation.c:13:10:13:25 | Chi | field_conflation.c:19:15:19:17 | taint_array output argument |
2+
| field_conflation.c:12:22:12:27 | call to getenv | field_conflation.c:13:3:13:18 | Chi |
3+
| field_conflation.c:12:22:12:34 | (const char *)... | field_conflation.c:13:3:13:18 | Chi |
4+
| field_conflation.c:13:3:13:18 | Chi | field_conflation.c:19:15:19:17 | taint_array output argument |
55
| field_conflation.c:19:15:19:17 | taint_array output argument | field_conflation.c:20:10:20:13 | (unsigned long)... |
66
| field_conflation.c:19:15:19:17 | taint_array output argument | field_conflation.c:20:13:20:13 | x |
77
| field_conflation.c:19:15:19:17 | taint_array output argument | field_conflation.c:20:13:20:13 | x |
@@ -71,7 +71,7 @@ edges
7171
nodes
7272
| field_conflation.c:12:22:12:27 | call to getenv | semmle.label | call to getenv |
7373
| field_conflation.c:12:22:12:34 | (const char *)... | semmle.label | (const char *)... |
74-
| field_conflation.c:13:10:13:25 | Chi | semmle.label | Chi |
74+
| field_conflation.c:13:3:13:18 | Chi | semmle.label | Chi |
7575
| field_conflation.c:19:15:19:17 | taint_array output argument | semmle.label | taint_array output argument |
7676
| field_conflation.c:20:10:20:13 | (unsigned long)... | semmle.label | (unsigned long)... |
7777
| field_conflation.c:20:10:20:13 | (unsigned long)... | semmle.label | (unsigned long)... |
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
int atoi(const char *nptr);
22
void *malloc(unsigned long size);
33
char *getenv(const char *name);
4-
void *memcpy(void *dst, void *src, unsigned long size);
54

6-
struct ContainsArray {
7-
int arr[16];
5+
6+
struct XY {
87
int x;
8+
int y;
99
};
1010

11-
void taint_array(struct ContainsArray *ca, int offset) {
11+
void taint_array(struct XY *xyp) {
1212
int tainted = atoi(getenv("VAR"));
13-
memcpy(ca->arr + offset, &tainted, sizeof(int));
13+
xyp->y = tainted;
1414
}
1515

16-
void test_conflated_fields3(int arbitrary) {
17-
struct ContainsArray ca;
18-
ca.x = 4;
19-
taint_array(&ca, arbitrary);
20-
malloc(ca.x); // not tainted [FALSE POSITIVE]
16+
void test_conflated_fields3(void) {
17+
struct XY xy;
18+
xy.x = 4;
19+
taint_array(&xy);
20+
malloc(xy.x); // not tainted [FALSE POSITIVE]
2121
}

0 commit comments

Comments
 (0)