Skip to content

Commit 8f702d4

Browse files
committed
C++: Override toString on argument indirections
Without this override, end users would see the string `BufferReadSideEffect` in path explanations.
1 parent 10dfa49 commit 8f702d4

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ class DefinitionByReferenceNode extends InstructionNode {
387387
}
388388
}
389389

390+
/**
391+
* A node representing the memory pointed to by a function argument.
392+
*
393+
* This class exists only in order to override `toString`, which would
394+
* otherwise be the default implementation inherited from `InstructionNode`.
395+
*/
396+
private class ArgumentIndirectionNode extends InstructionNode {
397+
override ReadSideEffectInstruction instr;
398+
399+
override string toString() {
400+
result = "Argument " + instr.getIndex() + " indirection"
401+
}
402+
}
403+
390404
/**
391405
* A `Node` corresponding to a variable in the program, as opposed to the
392406
* value of that variable at some particular point. This can be used for

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
edges
22
| A.cpp:98:12:98:18 | new | A.cpp:100:5:100:13 | Store |
3-
| A.cpp:100:5:100:13 | Chi [a] | A.cpp:101:8:101:9 | BufferReadSideEffect [a] |
3+
| A.cpp:100:5:100:13 | Chi [a] | A.cpp:101:8:101:9 | Argument 0 indirection [a] |
44
| A.cpp:100:5:100:13 | Store | A.cpp:100:5:100:13 | Chi [a] |
5-
| A.cpp:101:8:101:9 | BufferReadSideEffect [a] | A.cpp:103:14:103:14 | *c [a] |
5+
| A.cpp:101:8:101:9 | Argument 0 indirection [a] | A.cpp:103:14:103:14 | *c [a] |
66
| A.cpp:103:14:103:14 | *c [a] | A.cpp:107:16:107:16 | a |
77
| A.cpp:103:14:103:14 | *c [a] | A.cpp:107:16:107:16 | a |
88
| A.cpp:107:16:107:16 | a | A.cpp:107:12:107:16 | (void *)... |
@@ -32,9 +32,9 @@ edges
3232
| aliasing.cpp:79:11:79:20 | call to user_input | aliasing.cpp:80:12:80:13 | m1 |
3333
| aliasing.cpp:86:10:86:19 | call to user_input | aliasing.cpp:87:12:87:13 | m1 |
3434
| aliasing.cpp:92:12:92:21 | call to user_input | aliasing.cpp:93:12:93:13 | m1 |
35-
| by_reference.cpp:68:17:68:18 | nonMemberSetA output argument [a] | by_reference.cpp:69:22:69:23 | BufferReadSideEffect [a] |
35+
| by_reference.cpp:68:17:68:18 | nonMemberSetA output argument [a] | by_reference.cpp:69:22:69:23 | Argument 0 indirection [a] |
3636
| by_reference.cpp:68:21:68:30 | call to user_input | by_reference.cpp:68:17:68:18 | nonMemberSetA output argument [a] |
37-
| by_reference.cpp:69:22:69:23 | BufferReadSideEffect [a] | by_reference.cpp:69:8:69:20 | call to nonMemberGetA |
37+
| by_reference.cpp:69:22:69:23 | Argument 0 indirection [a] | by_reference.cpp:69:8:69:20 | call to nonMemberGetA |
3838
| by_reference.cpp:84:3:84:25 | Chi [a] | by_reference.cpp:102:21:102:39 | taint_inner_a_ptr output argument [a] |
3939
| by_reference.cpp:84:3:84:25 | Chi [a] | by_reference.cpp:106:21:106:41 | taint_inner_a_ptr output argument [a] |
4040
| by_reference.cpp:84:3:84:25 | Store | by_reference.cpp:84:3:84:25 | Chi [a] |
@@ -54,26 +54,26 @@ edges
5454
| simple.cpp:65:5:65:22 | Store [i] | simple.cpp:66:12:66:12 | Store [i] |
5555
| simple.cpp:65:11:65:20 | call to user_input | simple.cpp:65:5:65:22 | Store [i] |
5656
| simple.cpp:66:12:66:12 | Store [i] | simple.cpp:67:13:67:13 | i |
57-
| simple.cpp:83:9:83:28 | Chi [f1] | simple.cpp:84:14:84:20 | BufferReadSideEffect [f1] |
57+
| simple.cpp:83:9:83:28 | Chi [f1] | simple.cpp:84:14:84:20 | Argument -1 indirection [f1] |
5858
| simple.cpp:83:9:83:28 | Store | simple.cpp:83:9:83:28 | Chi [f1] |
5959
| simple.cpp:83:17:83:26 | call to user_input | simple.cpp:83:9:83:28 | Store |
60-
| simple.cpp:84:14:84:20 | BufferReadSideEffect [f1] | simple.cpp:84:14:84:20 | call to getf2f1 |
60+
| simple.cpp:84:14:84:20 | Argument -1 indirection [f1] | simple.cpp:84:14:84:20 | call to getf2f1 |
6161
| struct_init.c:14:24:14:25 | *ab [a] | struct_init.c:15:12:15:12 | a |
62-
| struct_init.c:20:20:20:29 | Chi [a] | struct_init.c:24:10:24:12 | BufferReadSideEffect [a] |
62+
| struct_init.c:20:20:20:29 | Chi [a] | struct_init.c:24:10:24:12 | Argument 0 indirection [a] |
6363
| struct_init.c:20:20:20:29 | Store | struct_init.c:20:20:20:29 | Chi [a] |
6464
| struct_init.c:20:20:20:29 | call to user_input | struct_init.c:20:20:20:29 | Store |
6565
| struct_init.c:20:20:20:29 | call to user_input | struct_init.c:22:11:22:11 | a |
66-
| struct_init.c:24:10:24:12 | BufferReadSideEffect [a] | struct_init.c:14:24:14:25 | *ab [a] |
67-
| struct_init.c:27:7:27:16 | Chi [a] | struct_init.c:36:10:36:24 | BufferReadSideEffect [a] |
66+
| struct_init.c:24:10:24:12 | Argument 0 indirection [a] | struct_init.c:14:24:14:25 | *ab [a] |
67+
| struct_init.c:27:7:27:16 | Chi [a] | struct_init.c:36:10:36:24 | Argument 0 indirection [a] |
6868
| struct_init.c:27:7:27:16 | Store | struct_init.c:27:7:27:16 | Chi [a] |
6969
| struct_init.c:27:7:27:16 | call to user_input | struct_init.c:27:7:27:16 | Store |
7070
| struct_init.c:27:7:27:16 | call to user_input | struct_init.c:31:23:31:23 | a |
71-
| struct_init.c:36:10:36:24 | BufferReadSideEffect [a] | struct_init.c:14:24:14:25 | *ab [a] |
71+
| struct_init.c:36:10:36:24 | Argument 0 indirection [a] | struct_init.c:14:24:14:25 | *ab [a] |
7272
nodes
7373
| A.cpp:98:12:98:18 | new | semmle.label | new |
7474
| A.cpp:100:5:100:13 | Chi [a] | semmle.label | Chi [a] |
7575
| A.cpp:100:5:100:13 | Store | semmle.label | Store |
76-
| A.cpp:101:8:101:9 | BufferReadSideEffect [a] | semmle.label | BufferReadSideEffect [a] |
76+
| A.cpp:101:8:101:9 | Argument 0 indirection [a] | semmle.label | Argument 0 indirection [a] |
7777
| A.cpp:103:14:103:14 | *c [a] | semmle.label | *c [a] |
7878
| A.cpp:107:12:107:16 | (void *)... | semmle.label | (void *)... |
7979
| A.cpp:107:16:107:16 | a | semmle.label | a |
@@ -116,7 +116,7 @@ nodes
116116
| by_reference.cpp:68:17:68:18 | nonMemberSetA output argument [a] | semmle.label | nonMemberSetA output argument [a] |
117117
| by_reference.cpp:68:21:68:30 | call to user_input | semmle.label | call to user_input |
118118
| by_reference.cpp:69:8:69:20 | call to nonMemberGetA | semmle.label | call to nonMemberGetA |
119-
| by_reference.cpp:69:22:69:23 | BufferReadSideEffect [a] | semmle.label | BufferReadSideEffect [a] |
119+
| by_reference.cpp:69:22:69:23 | Argument 0 indirection [a] | semmle.label | Argument 0 indirection [a] |
120120
| by_reference.cpp:84:3:84:25 | Chi [a] | semmle.label | Chi [a] |
121121
| by_reference.cpp:84:3:84:25 | Store | semmle.label | Store |
122122
| by_reference.cpp:84:14:84:23 | call to user_input | semmle.label | call to user_input |
@@ -142,20 +142,20 @@ nodes
142142
| simple.cpp:83:9:83:28 | Chi [f1] | semmle.label | Chi [f1] |
143143
| simple.cpp:83:9:83:28 | Store | semmle.label | Store |
144144
| simple.cpp:83:17:83:26 | call to user_input | semmle.label | call to user_input |
145-
| simple.cpp:84:14:84:20 | BufferReadSideEffect [f1] | semmle.label | BufferReadSideEffect [f1] |
145+
| simple.cpp:84:14:84:20 | Argument -1 indirection [f1] | semmle.label | Argument -1 indirection [f1] |
146146
| simple.cpp:84:14:84:20 | call to getf2f1 | semmle.label | call to getf2f1 |
147147
| struct_init.c:14:24:14:25 | *ab [a] | semmle.label | *ab [a] |
148148
| struct_init.c:15:12:15:12 | a | semmle.label | a |
149149
| struct_init.c:20:20:20:29 | Chi [a] | semmle.label | Chi [a] |
150150
| struct_init.c:20:20:20:29 | Store | semmle.label | Store |
151151
| struct_init.c:20:20:20:29 | call to user_input | semmle.label | call to user_input |
152152
| struct_init.c:22:11:22:11 | a | semmle.label | a |
153-
| struct_init.c:24:10:24:12 | BufferReadSideEffect [a] | semmle.label | BufferReadSideEffect [a] |
153+
| struct_init.c:24:10:24:12 | Argument 0 indirection [a] | semmle.label | Argument 0 indirection [a] |
154154
| struct_init.c:27:7:27:16 | Chi [a] | semmle.label | Chi [a] |
155155
| struct_init.c:27:7:27:16 | Store | semmle.label | Store |
156156
| struct_init.c:27:7:27:16 | call to user_input | semmle.label | call to user_input |
157157
| struct_init.c:31:23:31:23 | a | semmle.label | a |
158-
| struct_init.c:36:10:36:24 | BufferReadSideEffect [a] | semmle.label | BufferReadSideEffect [a] |
158+
| struct_init.c:36:10:36:24 | Argument 0 indirection [a] | semmle.label | Argument 0 indirection [a] |
159159
#select
160160
| A.cpp:107:12:107:16 | (void *)... | A.cpp:98:12:98:18 | new | A.cpp:107:12:107:16 | (void *)... | (void *)... flows from $@ | A.cpp:98:12:98:18 | new | new |
161161
| A.cpp:107:16:107:16 | a | A.cpp:98:12:98:18 | new | A.cpp:107:16:107:16 | a | a flows from $@ | A.cpp:98:12:98:18 | new | new |

0 commit comments

Comments
 (0)