Skip to content

Commit 32ab636

Browse files
committed
C++: adjust test so size flows from malloc to field
1 parent fcd0bb1 commit 32ab636

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/array-access/ArrayAccessProductFlow.expected

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ edges
44
| test.cpp:19:9:19:16 | VariableAddress indirection [p] | test.cpp:31:9:31:11 | arr indirection [p] |
55
| test.cpp:19:9:19:16 | VariableAddress indirection [p] | test.cpp:35:9:35:11 | arr indirection [p] |
66
| test.cpp:19:9:19:16 | VariableAddress indirection [p] | test.cpp:50:18:50:25 | call to mk_array [p] |
7-
| test.cpp:22:5:22:24 | Store | test.cpp:22:9:22:9 | arr indirection [post update] [p] |
8-
| test.cpp:22:9:22:9 | arr indirection [post update] [p] | test.cpp:19:9:19:16 | VariableAddress indirection [p] |
9-
| test.cpp:22:13:22:18 | call to malloc | test.cpp:22:5:22:24 | Store |
7+
| test.cpp:21:5:21:24 | Store | test.cpp:21:9:21:9 | arr indirection [post update] [p] |
8+
| test.cpp:21:9:21:9 | arr indirection [post update] [p] | test.cpp:19:9:19:16 | VariableAddress indirection [p] |
9+
| test.cpp:21:13:21:18 | call to malloc | test.cpp:21:5:21:24 | Store |
1010
| test.cpp:31:9:31:11 | arr indirection [p] | test.cpp:31:13:31:13 | p |
1111
| test.cpp:31:13:31:13 | p | test.cpp:31:13:31:13 | Load |
1212
| test.cpp:35:9:35:11 | arr indirection [p] | test.cpp:35:13:35:13 | p |
@@ -18,19 +18,19 @@ edges
1818
| test.cpp:45:9:45:11 | arr indirection [p] | test.cpp:45:13:45:13 | p |
1919
| test.cpp:45:13:45:13 | p | test.cpp:45:13:45:13 | Load |
2020
| test.cpp:50:18:50:25 | call to mk_array [p] | test.cpp:39:27:39:29 | arr [p] |
21-
| test.cpp:56:5:56:24 | Store | test.cpp:56:9:56:9 | arr indirection [post update] [p] |
22-
| test.cpp:56:9:56:9 | arr indirection [post update] [p] | test.cpp:59:9:59:11 | arr indirection [p] |
23-
| test.cpp:56:9:56:9 | arr indirection [post update] [p] | test.cpp:63:9:63:11 | arr indirection [p] |
24-
| test.cpp:56:13:56:18 | call to malloc | test.cpp:56:5:56:24 | Store |
21+
| test.cpp:55:5:55:24 | Store | test.cpp:55:9:55:9 | arr indirection [post update] [p] |
22+
| test.cpp:55:9:55:9 | arr indirection [post update] [p] | test.cpp:59:9:59:11 | arr indirection [p] |
23+
| test.cpp:55:9:55:9 | arr indirection [post update] [p] | test.cpp:63:9:63:11 | arr indirection [p] |
24+
| test.cpp:55:13:55:18 | call to malloc | test.cpp:55:5:55:24 | Store |
2525
| test.cpp:59:9:59:11 | arr indirection [p] | test.cpp:59:13:59:13 | p |
2626
| test.cpp:59:13:59:13 | p | test.cpp:59:13:59:13 | Load |
2727
| test.cpp:63:9:63:11 | arr indirection [p] | test.cpp:63:13:63:13 | p |
2828
| test.cpp:63:13:63:13 | p | test.cpp:63:13:63:13 | Load |
2929
| test.cpp:67:10:67:19 | VariableAddress indirection [p] | test.cpp:76:20:76:29 | Call indirection [p] |
3030
| test.cpp:67:10:67:19 | VariableAddress indirection [p] | test.cpp:98:18:98:27 | call to mk_array_p indirection [p] |
31-
| test.cpp:70:5:70:25 | Store | test.cpp:70:10:70:10 | Load indirection [post update] [p] |
32-
| test.cpp:70:10:70:10 | Load indirection [post update] [p] | test.cpp:67:10:67:19 | VariableAddress indirection [p] |
33-
| test.cpp:70:14:70:19 | call to malloc | test.cpp:70:5:70:25 | Store |
31+
| test.cpp:69:5:69:25 | Store | test.cpp:69:10:69:10 | Load indirection [post update] [p] |
32+
| test.cpp:69:10:69:10 | Load indirection [post update] [p] | test.cpp:67:10:67:19 | VariableAddress indirection [p] |
33+
| test.cpp:69:14:69:19 | call to malloc | test.cpp:69:5:69:25 | Store |
3434
| test.cpp:76:20:76:29 | Call indirection [p] | test.cpp:79:9:79:11 | Load indirection [p] |
3535
| test.cpp:76:20:76:29 | Call indirection [p] | test.cpp:83:9:83:11 | Load indirection [p] |
3636
| test.cpp:79:9:79:11 | Load indirection [p] | test.cpp:79:14:79:14 | p |
@@ -49,9 +49,9 @@ nodes
4949
| test.cpp:6:9:6:11 | Load | semmle.label | Load |
5050
| test.cpp:10:9:10:11 | Load | semmle.label | Load |
5151
| test.cpp:19:9:19:16 | VariableAddress indirection [p] | semmle.label | VariableAddress indirection [p] |
52-
| test.cpp:22:5:22:24 | Store | semmle.label | Store |
53-
| test.cpp:22:9:22:9 | arr indirection [post update] [p] | semmle.label | arr indirection [post update] [p] |
54-
| test.cpp:22:13:22:18 | call to malloc | semmle.label | call to malloc |
52+
| test.cpp:21:5:21:24 | Store | semmle.label | Store |
53+
| test.cpp:21:9:21:9 | arr indirection [post update] [p] | semmle.label | arr indirection [post update] [p] |
54+
| test.cpp:21:13:21:18 | call to malloc | semmle.label | call to malloc |
5555
| test.cpp:31:9:31:11 | arr indirection [p] | semmle.label | arr indirection [p] |
5656
| test.cpp:31:13:31:13 | Load | semmle.label | Load |
5757
| test.cpp:31:13:31:13 | p | semmle.label | p |
@@ -66,19 +66,19 @@ nodes
6666
| test.cpp:45:13:45:13 | Load | semmle.label | Load |
6767
| test.cpp:45:13:45:13 | p | semmle.label | p |
6868
| test.cpp:50:18:50:25 | call to mk_array [p] | semmle.label | call to mk_array [p] |
69-
| test.cpp:56:5:56:24 | Store | semmle.label | Store |
70-
| test.cpp:56:9:56:9 | arr indirection [post update] [p] | semmle.label | arr indirection [post update] [p] |
71-
| test.cpp:56:13:56:18 | call to malloc | semmle.label | call to malloc |
69+
| test.cpp:55:5:55:24 | Store | semmle.label | Store |
70+
| test.cpp:55:9:55:9 | arr indirection [post update] [p] | semmle.label | arr indirection [post update] [p] |
71+
| test.cpp:55:13:55:18 | call to malloc | semmle.label | call to malloc |
7272
| test.cpp:59:9:59:11 | arr indirection [p] | semmle.label | arr indirection [p] |
7373
| test.cpp:59:13:59:13 | Load | semmle.label | Load |
7474
| test.cpp:59:13:59:13 | p | semmle.label | p |
7575
| test.cpp:63:9:63:11 | arr indirection [p] | semmle.label | arr indirection [p] |
7676
| test.cpp:63:13:63:13 | Load | semmle.label | Load |
7777
| test.cpp:63:13:63:13 | p | semmle.label | p |
7878
| test.cpp:67:10:67:19 | VariableAddress indirection [p] | semmle.label | VariableAddress indirection [p] |
79-
| test.cpp:70:5:70:25 | Store | semmle.label | Store |
80-
| test.cpp:70:10:70:10 | Load indirection [post update] [p] | semmle.label | Load indirection [post update] [p] |
81-
| test.cpp:70:14:70:19 | call to malloc | semmle.label | call to malloc |
79+
| test.cpp:69:5:69:25 | Store | semmle.label | Store |
80+
| test.cpp:69:10:69:10 | Load indirection [post update] [p] | semmle.label | Load indirection [post update] [p] |
81+
| test.cpp:69:14:69:19 | call to malloc | semmle.label | call to malloc |
8282
| test.cpp:76:20:76:29 | Call indirection [p] | semmle.label | Call indirection [p] |
8383
| test.cpp:79:9:79:11 | Load indirection [p] | semmle.label | Load indirection [p] |
8484
| test.cpp:79:14:79:14 | Load | semmle.label | Load |
@@ -98,3 +98,15 @@ subpaths
9898
#select
9999
| test.cpp:10:9:10:11 | Load | test.cpp:4:17:4:22 | call to malloc | test.cpp:10:9:10:11 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:4:17:4:22 | call to malloc | test.cpp:4:17:4:22 | call to malloc | test.cpp:5:25:5:28 | Load | test.cpp:5:25:5:28 | Load |
100100
| test.cpp:10:9:10:11 | Load | test.cpp:4:17:4:22 | call to malloc | test.cpp:10:9:10:11 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:4:17:4:22 | call to malloc | test.cpp:4:17:4:22 | call to malloc | test.cpp:9:26:9:29 | Load | test.cpp:9:26:9:29 | Load |
101+
| test.cpp:35:13:35:13 | Load | test.cpp:21:13:21:18 | call to malloc | test.cpp:35:13:35:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:21:13:21:18 | call to malloc | test.cpp:21:13:21:18 | call to malloc | test.cpp:30:29:30:32 | Load | test.cpp:30:29:30:32 | Load |
102+
| test.cpp:35:13:35:13 | Load | test.cpp:21:13:21:18 | call to malloc | test.cpp:35:13:35:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:21:13:21:18 | call to malloc | test.cpp:21:13:21:18 | call to malloc | test.cpp:34:30:34:33 | Load | test.cpp:34:30:34:33 | Load |
103+
| test.cpp:45:13:45:13 | Load | test.cpp:21:13:21:18 | call to malloc | test.cpp:45:13:45:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:21:13:21:18 | call to malloc | test.cpp:21:13:21:18 | call to malloc | test.cpp:40:29:40:32 | Load | test.cpp:40:29:40:32 | Load |
104+
| test.cpp:45:13:45:13 | Load | test.cpp:21:13:21:18 | call to malloc | test.cpp:45:13:45:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:21:13:21:18 | call to malloc | test.cpp:21:13:21:18 | call to malloc | test.cpp:44:30:44:33 | Load | test.cpp:44:30:44:33 | Load |
105+
| test.cpp:63:13:63:13 | Load | test.cpp:55:13:55:18 | call to malloc | test.cpp:63:13:63:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:55:13:55:18 | call to malloc | test.cpp:55:13:55:18 | call to malloc | test.cpp:56:5:56:19 | Store | test.cpp:56:5:56:19 | Store |
106+
| test.cpp:63:13:63:13 | Load | test.cpp:55:13:55:18 | call to malloc | test.cpp:63:13:63:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:55:13:55:18 | call to malloc | test.cpp:55:13:55:18 | call to malloc | test.cpp:56:5:56:19 | Store | test.cpp:56:5:56:19 | Store |
107+
| test.cpp:63:13:63:13 | Load | test.cpp:55:13:55:18 | call to malloc | test.cpp:63:13:63:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:55:13:55:18 | call to malloc | test.cpp:55:13:55:18 | call to malloc | test.cpp:56:16:56:19 | Load | test.cpp:56:16:56:19 | Load |
108+
| test.cpp:63:13:63:13 | Load | test.cpp:55:13:55:18 | call to malloc | test.cpp:63:13:63:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:55:13:55:18 | call to malloc | test.cpp:55:13:55:18 | call to malloc | test.cpp:58:29:58:32 | Load | test.cpp:58:29:58:32 | Load |
109+
| test.cpp:63:13:63:13 | Load | test.cpp:55:13:55:18 | call to malloc | test.cpp:63:13:63:13 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:55:13:55:18 | call to malloc | test.cpp:55:13:55:18 | call to malloc | test.cpp:62:30:62:33 | Load | test.cpp:62:30:62:33 | Load |
110+
| test.cpp:83:14:83:14 | Load | test.cpp:69:14:69:19 | call to malloc | test.cpp:83:14:83:14 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:69:14:69:19 | call to malloc | test.cpp:69:14:69:19 | call to malloc | test.cpp:82:31:82:34 | Load | test.cpp:82:31:82:34 | Load |
111+
| test.cpp:93:14:93:14 | Load | test.cpp:69:14:69:19 | call to malloc | test.cpp:93:14:93:14 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:69:14:69:19 | call to malloc | test.cpp:69:14:69:19 | call to malloc | test.cpp:88:30:88:33 | Load | test.cpp:88:30:88:33 | Load |
112+
| test.cpp:93:14:93:14 | Load | test.cpp:69:14:69:19 | call to malloc | test.cpp:93:14:93:14 | Load | off-by one error allocated at $@ bounded by $@ | test.cpp:69:14:69:19 | call to malloc | test.cpp:69:14:69:19 | call to malloc | test.cpp:92:31:92:34 | Load | test.cpp:92:31:92:34 | Load |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/array-access/test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ typedef struct {
1818

1919
array_t mk_array(int size) {
2020
array_t arr;
21-
arr.size = size;
2221
arr.p = malloc(size);
22+
arr.size = size;
2323

2424
return arr;
2525
}
@@ -32,7 +32,7 @@ void test2(int size) {
3232
}
3333

3434
for (int i = 0; i <= arr.size; i++) {
35-
arr.p[i] = i; // BAD [NOT DETECTED]
35+
arr.p[i] = i; // BAD
3636
}
3737
}
3838

@@ -42,7 +42,7 @@ void test3_callee(array_t arr) {
4242
}
4343

4444
for (int i = 0; i <= arr.size; i++) {
45-
arr.p[i] = i; // BAD [NOT DETECTED]
45+
arr.p[i] = i; // BAD
4646
}
4747
}
4848

@@ -52,8 +52,8 @@ void test3(int size) {
5252

5353
void test4(int size) {
5454
array_t arr;
55-
arr.size = size;
5655
arr.p = malloc(size);
56+
arr.size = size;
5757

5858
for (int i = 0; i < arr.size; i++) {
5959
arr.p[i] = 0; // GOOD
@@ -66,8 +66,8 @@ void test4(int size) {
6666

6767
array_t *mk_array_p(int size) {
6868
array_t *arr = (array_t*) malloc(sizeof(array_t));
69-
arr->size = size;
7069
arr->p = malloc(size);
70+
arr->size = size;
7171

7272
return arr;
7373
}

0 commit comments

Comments
 (0)