Skip to content

Commit 6fca23b

Browse files
committed
C++: Demonstrate lack of flow through single-field structs
1 parent 243dea7 commit 6fca23b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cpp/ql/test/library-tests/dataflow/fields/flow.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ edges
221221
| simple.cpp:48:9:48:9 | g [b_] | simple.cpp:26:15:26:15 | f [b_] |
222222
| simple.cpp:51:9:51:9 | h [a_] | simple.cpp:26:15:26:15 | f [a_] |
223223
| simple.cpp:51:9:51:9 | h [b_] | simple.cpp:26:15:26:15 | f [b_] |
224+
| simple.cpp:65:5:65:5 | a [post update] [i] | simple.cpp:67:10:67:11 | a2 [i] |
225+
| simple.cpp:65:5:65:22 | ... = ... | simple.cpp:65:5:65:5 | a [post update] [i] |
226+
| simple.cpp:65:11:65:20 | call to user_input | simple.cpp:65:5:65:22 | ... = ... |
227+
| simple.cpp:67:10:67:11 | a2 [i] | simple.cpp:67:13:67:13 | i |
224228
| struct_init.c:14:24:14:25 | ab [a] | struct_init.c:15:8:15:9 | ab [a] |
225229
| struct_init.c:15:8:15:9 | ab [a] | struct_init.c:15:12:15:12 | a |
226230
| struct_init.c:20:17:20:36 | {...} [a] | struct_init.c:22:8:22:9 | ab [a] |
@@ -504,6 +508,11 @@ nodes
504508
| simple.cpp:48:9:48:9 | g [b_] | semmle.label | g [b_] |
505509
| simple.cpp:51:9:51:9 | h [a_] | semmle.label | h [a_] |
506510
| simple.cpp:51:9:51:9 | h [b_] | semmle.label | h [b_] |
511+
| simple.cpp:65:5:65:5 | a [post update] [i] | semmle.label | a [post update] [i] |
512+
| simple.cpp:65:5:65:22 | ... = ... | semmle.label | ... = ... |
513+
| simple.cpp:65:11:65:20 | call to user_input | semmle.label | call to user_input |
514+
| simple.cpp:67:10:67:11 | a2 [i] | semmle.label | a2 [i] |
515+
| simple.cpp:67:13:67:13 | i | semmle.label | i |
507516
| struct_init.c:14:24:14:25 | ab [a] | semmle.label | ab [a] |
508517
| struct_init.c:15:8:15:9 | ab [a] | semmle.label | ab [a] |
509518
| struct_init.c:15:12:15:12 | a | semmle.label | a |
@@ -580,6 +589,7 @@ nodes
580589
| simple.cpp:28:12:28:12 | call to a | simple.cpp:41:12:41:21 | call to user_input | simple.cpp:28:12:28:12 | call to a | call to a flows from $@ | simple.cpp:41:12:41:21 | call to user_input | call to user_input |
581590
| simple.cpp:29:12:29:12 | call to b | simple.cpp:40:12:40:21 | call to user_input | simple.cpp:29:12:29:12 | call to b | call to b flows from $@ | simple.cpp:40:12:40:21 | call to user_input | call to user_input |
582591
| simple.cpp:29:12:29:12 | call to b | simple.cpp:42:12:42:21 | call to user_input | simple.cpp:29:12:29:12 | call to b | call to b flows from $@ | simple.cpp:42:12:42:21 | call to user_input | call to user_input |
592+
| simple.cpp:67:13:67:13 | i | simple.cpp:65:11:65:20 | call to user_input | simple.cpp:67:13:67:13 | i | i flows from $@ | simple.cpp:65:11:65:20 | call to user_input | call to user_input |
583593
| struct_init.c:15:12:15:12 | a | struct_init.c:20:20:20:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:20:20:20:29 | call to user_input | call to user_input |
584594
| struct_init.c:15:12:15:12 | a | struct_init.c:27:7:27:16 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:27:7:27:16 | call to user_input | call to user_input |
585595
| struct_init.c:15:12:15:12 | a | struct_init.c:40:20:40:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:40:20:40:29 | call to user_input | call to user_input |

cpp/ql/test/library-tests/dataflow/fields/simple.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,18 @@ void foo()
5353
// Nothing should alert
5454
bar(i);
5555
}
56+
57+
struct A
58+
{
59+
int i;
60+
};
61+
62+
void single_field_test()
63+
{
64+
A a;
65+
a.i = user_input();
66+
A a2 = a;
67+
sink(a2.i);
68+
}
69+
5670
} // namespace Simple

0 commit comments

Comments
 (0)