Skip to content

Commit 40529d1

Browse files
committed
DataFlow: Add the concept of selected locations
This extension allows queries to be diff-informed even when the elements they select are different from the sources and sinks found by data flow.
1 parent 772b972 commit 40529d1

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,28 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
442442
* are used directly in a query result.
443443
*/
444444
default predicate observeDiffInformedIncrementalMode() { none() }
445+
446+
/**
447+
* Gets a location that will be associated with the given `source` in a
448+
* diff-informed query that uses this configuration (see
449+
* `observeDiffInformedIncrementalMode`). By default, this is the location
450+
* of the source itself, but this predicate should include any locations
451+
* that are reported as the primary-location of the query or as an
452+
* additional location ("$@" interpolation). For a query that doesn't
453+
* report the source at all, this predicate can be `none()`.
454+
*/
455+
default Location getASelectedSourceLocation(Node source) { result = source.getLocation() }
456+
457+
/**
458+
* Gets a location that will be associated with the given `sink` in a
459+
* diff-informed query that uses this configuration (see
460+
* `observeDiffInformedIncrementalMode`). By default, this is the location
461+
* of the sink itself, but this predicate should include any locations
462+
* that are reported as the primary-location of the query or as an
463+
* additional location ("$@" interpolation). For a query that doesn't
464+
* report the sink at all, this predicate can be `none()`.
465+
*/
466+
default Location getASelectedSinkLocation(Node sink) { result = sink.getLocation() }
445467
}
446468

447469
/** An input configuration for data flow using flow state. */
@@ -569,6 +591,28 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
569591
* are used directly in a query result.
570592
*/
571593
default predicate observeDiffInformedIncrementalMode() { none() }
594+
595+
/**
596+
* Gets a location that will be associated with the given `source` in a
597+
* diff-informed query that uses this configuration (see
598+
* `observeDiffInformedIncrementalMode`). By default, this is the location
599+
* of the source itself, but this predicate should include any locations
600+
* that are reported as the primary-location of the query or as an
601+
* additional location ("$@" interpolation). For a query that doesn't
602+
* report the source at all, this predicate can be `none()`.
603+
*/
604+
default Location getASelectedSourceLocation(Node source) { result = source.getLocation() }
605+
606+
/**
607+
* Gets a location that will be associated with the given `sink` in a
608+
* diff-informed query that uses this configuration (see
609+
* `observeDiffInformedIncrementalMode`). By default, this is the location
610+
* of the sink itself, but this predicate should include any locations
611+
* that are reported as the primary-location of the query or as an
612+
* additional location ("$@" interpolation). For a query that doesn't
613+
* report the sink at all, this predicate can be `none()`.
614+
*/
615+
default Location getASelectedSinkLocation(Node sink) { result = sink.getLocation() }
572616
}
573617
}
574618

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
137137
* are used directly in a query result.
138138
*/
139139
predicate observeDiffInformedIncrementalMode();
140+
141+
Location getASelectedSourceLocation(Node source);
142+
143+
Location getASelectedSinkLocation(Node sink);
140144
}
141145

142146
/**
@@ -177,7 +181,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
177181
private predicate isFilteredSource(Node source) {
178182
Config::isSource(source, _) and
179183
if Config::observeDiffInformedIncrementalMode()
180-
then AlertFiltering::filterByLocation(source.getLocation())
184+
then AlertFiltering::filterByLocation(Config::getASelectedSourceLocation(source))
181185
else any()
182186
}
183187

@@ -188,7 +192,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
188192
Config::isSink(sink)
189193
) and
190194
if Config::observeDiffInformedIncrementalMode()
191-
then AlertFiltering::filterByLocation(sink.getLocation())
195+
then AlertFiltering::filterByLocation(Config::getASelectedSinkLocation(sink))
192196
else any()
193197
}
194198

0 commit comments

Comments
 (0)