Skip to content

Commit 41d233f

Browse files
committed
C++: Make the 'definition by reference'-node in 'foo(a.b);' a source in the 'FieldConfiguration' configuration.
1 parent a082172 commit 41d233f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,12 @@ private module FieldFlow {
735735
private class FieldConfiguration extends Configuration {
736736
FieldConfiguration() { this = "FieldConfiguration" }
737737

738-
override predicate isSource(Node source) { storeStep(source, _, _) }
738+
override predicate isSource(Node source) {
739+
storeStep(source, _, _)
740+
or
741+
// Also mark `foo(a.b);` as a source when `a.b` may be overwritten by `foo`.
742+
readStep(_, _, any(Node node | node.asExpr() = source.asDefiningArgument()))
743+
}
739744

740745
override predicate isSink(Node sink) { readStep(_, _, sink) }
741746

cpp/ql/test/library-tests/dataflow/dataflow-tests/localFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@
7373
| test.cpp:480:67:480:67 | s | test.cpp:481:21:481:21 | s |
7474
| test.cpp:480:67:480:67 | s | test.cpp:482:20:482:20 | s |
7575
| test.cpp:481:21:481:21 | s [post update] | test.cpp:482:20:482:20 | s |
76+
| test.cpp:481:24:481:30 | ref arg content | test.cpp:482:23:482:29 | content |
7677
| test.cpp:482:23:482:29 | content | test.cpp:483:9:483:17 | p_content |

0 commit comments

Comments
 (0)