Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66d49a4

Browse files
authored
Merge pull request #2546 from MathiasVP/arguments-source-qltest
C++: Added test for 333d0a6
2 parents 8ad11b9 + 1d3ee71 commit 66d49a4

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class buf
2+
{
3+
public:
4+
char *buffer;
5+
};
6+
7+
class packet
8+
{
9+
public:
10+
buf data;
11+
};
12+
13+
typedef long ssize_t;
14+
15+
ssize_t argument_source(void *buf);
16+
17+
void sink(char *b);
18+
19+
void handlePacket(packet *p)
20+
{
21+
sink(p->data.buffer);
22+
}
23+
24+
void f(buf* b)
25+
{
26+
char *raw;
27+
packet p;
28+
argument_source(raw);
29+
argument_source(b->buffer);
30+
argument_source(p.data.buffer);
31+
sink(raw);
32+
sink(b->buffer);
33+
handlePacket(&p);
34+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ edges
122122
| D.cpp:64:10:64:17 | boxfield [box, elem] | D.cpp:64:20:64:22 | box [elem] |
123123
| D.cpp:64:10:64:17 | this [boxfield, box, ... (3)] | D.cpp:64:10:64:17 | boxfield [box, elem] |
124124
| D.cpp:64:20:64:22 | box [elem] | D.cpp:64:25:64:28 | elem |
125+
| E.cpp:19:27:19:27 | p [data, buffer] | E.cpp:21:10:21:10 | p [data, buffer] |
126+
| E.cpp:21:10:21:10 | p [data, buffer] | E.cpp:21:13:21:16 | data [buffer] |
127+
| E.cpp:21:13:21:16 | data [buffer] | E.cpp:21:18:21:23 | buffer |
128+
| E.cpp:28:21:28:23 | ref arg raw | E.cpp:31:10:31:12 | raw |
129+
| E.cpp:29:21:29:21 | b [post update] [buffer] | E.cpp:32:10:32:10 | b [buffer] |
130+
| E.cpp:29:24:29:29 | ref arg buffer | E.cpp:29:21:29:21 | b [post update] [buffer] |
131+
| E.cpp:30:21:30:21 | p [post update] [data, buffer] | E.cpp:33:18:33:19 | & ... [data, buffer] |
132+
| E.cpp:30:23:30:26 | data [post update] [buffer] | E.cpp:30:21:30:21 | p [post update] [data, buffer] |
133+
| E.cpp:30:28:30:33 | ref arg buffer | E.cpp:30:23:30:26 | data [post update] [buffer] |
134+
| E.cpp:32:10:32:10 | b [buffer] | E.cpp:32:13:32:18 | buffer |
135+
| E.cpp:33:18:33:19 | & ... [data, buffer] | E.cpp:19:27:19:27 | p [data, buffer] |
125136
| aliasing.cpp:9:3:9:3 | s [post update] [m1] | aliasing.cpp:25:17:25:19 | ref arg & ... [m1] |
126137
| aliasing.cpp:9:3:9:22 | ... = ... | aliasing.cpp:9:3:9:3 | s [post update] [m1] |
127138
| aliasing.cpp:9:11:9:20 | call to user_input | aliasing.cpp:9:3:9:22 | ... = ... |
@@ -378,6 +389,20 @@ nodes
378389
| D.cpp:64:10:64:17 | this [boxfield, box, ... (3)] | semmle.label | this [boxfield, box, ... (3)] |
379390
| D.cpp:64:20:64:22 | box [elem] | semmle.label | box [elem] |
380391
| D.cpp:64:25:64:28 | elem | semmle.label | elem |
392+
| E.cpp:19:27:19:27 | p [data, buffer] | semmle.label | p [data, buffer] |
393+
| E.cpp:21:10:21:10 | p [data, buffer] | semmle.label | p [data, buffer] |
394+
| E.cpp:21:13:21:16 | data [buffer] | semmle.label | data [buffer] |
395+
| E.cpp:21:18:21:23 | buffer | semmle.label | buffer |
396+
| E.cpp:28:21:28:23 | ref arg raw | semmle.label | ref arg raw |
397+
| E.cpp:29:21:29:21 | b [post update] [buffer] | semmle.label | b [post update] [buffer] |
398+
| E.cpp:29:24:29:29 | ref arg buffer | semmle.label | ref arg buffer |
399+
| E.cpp:30:21:30:21 | p [post update] [data, buffer] | semmle.label | p [post update] [data, buffer] |
400+
| E.cpp:30:23:30:26 | data [post update] [buffer] | semmle.label | data [post update] [buffer] |
401+
| E.cpp:30:28:30:33 | ref arg buffer | semmle.label | ref arg buffer |
402+
| E.cpp:31:10:31:12 | raw | semmle.label | raw |
403+
| E.cpp:32:10:32:10 | b [buffer] | semmle.label | b [buffer] |
404+
| E.cpp:32:13:32:18 | buffer | semmle.label | buffer |
405+
| E.cpp:33:18:33:19 | & ... [data, buffer] | semmle.label | & ... [data, buffer] |
381406
| aliasing.cpp:9:3:9:3 | s [post update] [m1] | semmle.label | s [post update] [m1] |
382407
| aliasing.cpp:9:3:9:22 | ... = ... | semmle.label | ... = ... |
383408
| aliasing.cpp:9:11:9:20 | call to user_input | semmle.label | call to user_input |
@@ -532,6 +557,9 @@ nodes
532557
| D.cpp:22:25:22:31 | call to getElem | D.cpp:42:15:42:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:42:15:42:24 | new | new |
533558
| D.cpp:22:25:22:31 | call to getElem | D.cpp:49:15:49:24 | new | D.cpp:22:25:22:31 | call to getElem | call to getElem flows from $@ | D.cpp:49:15:49:24 | new | new |
534559
| D.cpp:64:25:64:28 | elem | D.cpp:56:15:56:24 | new | D.cpp:64:25:64:28 | elem | elem flows from $@ | D.cpp:56:15:56:24 | new | new |
560+
| E.cpp:21:18:21:23 | buffer | E.cpp:30:28:30:33 | ref arg buffer | E.cpp:21:18:21:23 | buffer | buffer flows from $@ | E.cpp:30:28:30:33 | ref arg buffer | ref arg buffer |
561+
| E.cpp:31:10:31:12 | raw | E.cpp:28:21:28:23 | ref arg raw | E.cpp:31:10:31:12 | raw | raw flows from $@ | E.cpp:28:21:28:23 | ref arg raw | ref arg raw |
562+
| E.cpp:32:13:32:18 | buffer | E.cpp:29:24:29:29 | ref arg buffer | E.cpp:32:13:32:18 | buffer | buffer flows from $@ | E.cpp:29:24:29:29 | ref arg buffer | ref arg buffer |
535563
| aliasing.cpp:29:11:29:12 | m1 | aliasing.cpp:9:11:9:20 | call to user_input | aliasing.cpp:29:11:29:12 | m1 | m1 flows from $@ | aliasing.cpp:9:11:9:20 | call to user_input | call to user_input |
536564
| aliasing.cpp:30:11:30:12 | m1 | aliasing.cpp:13:10:13:19 | call to user_input | aliasing.cpp:30:11:30:12 | m1 | m1 flows from $@ | aliasing.cpp:13:10:13:19 | call to user_input | call to user_input |
537565
| aliasing.cpp:62:14:62:15 | m1 | aliasing.cpp:60:11:60:20 | call to user_input | aliasing.cpp:62:14:62:15 | m1 | m1 flows from $@ | aliasing.cpp:60:11:60:20 | call to user_input | call to user_input |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class Conf extends Configuration {
1414
src.asExpr() instanceof NewExpr
1515
or
1616
src.asExpr().(Call).getTarget().hasName("user_input")
17+
or
18+
exists(FunctionCall fc |
19+
fc.getAnArgument() = src.asDefiningArgument() and
20+
fc.getTarget().hasName("argument_source")
21+
)
1722
}
1823

1924
override predicate isSink(Node sink) {

0 commit comments

Comments
 (0)