Skip to content

Commit e82e318

Browse files
committed
Data flow: Replace hasLocationInfo with getLocation
1 parent 35a8e7c commit e82e318

File tree

7 files changed

+86
-138
lines changed

7 files changed

+86
-138
lines changed

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44
* modules.
55
*/
66

7+
private import codeql.util.Location
8+
79
/** Provides language-specific data flow parameters. */
8-
signature module InputSig {
10+
signature module InputSig<LocationSig Location> {
911
/**
1012
* A node in the data flow graph.
1113
*/
1214
class Node {
1315
/** Gets a textual representation of this element. */
1416
string toString();
1517

16-
/**
17-
* Holds if this element is at the specified location.
18-
* The location spans column `startcolumn` of line `startline` to
19-
* column `endcolumn` of line `endline` in file `filepath`.
20-
* For more information, see
21-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
22-
*/
23-
predicate hasLocationInfo(
24-
string filepath, int startline, int startcolumn, int endline, int endcolumn
25-
);
18+
/** Gets the location of this node. */
19+
Location getLocation();
2620
}
2721

2822
class ParameterNode extends Node;
@@ -321,9 +315,9 @@ signature module InputSig {
321315
default predicate ignoreFieldFlowBranchLimit(DataFlowCallable c) { none() }
322316
}
323317

324-
module Configs<InputSig Lang> {
318+
module Configs<LocationSig Location, InputSig<Location> Lang> {
325319
private import Lang
326-
private import internal.DataFlowImplCommon::MakeImplCommon<Lang>
320+
private import internal.DataFlowImplCommon::MakeImplCommon<Location, Lang>
327321
import DataFlowImplCommonPublic
328322

329323
/** An input configuration for data flow. */
@@ -531,10 +525,10 @@ module Configs<InputSig Lang> {
531525
}
532526
}
533527

534-
module DataFlowMake<InputSig Lang> {
528+
module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
535529
private import Lang
536-
private import internal.DataFlowImpl::MakeImpl<Lang>
537-
import Configs<Lang>
530+
private import internal.DataFlowImpl::MakeImpl<Location, Lang>
531+
import Configs<Location, Lang>
538532

539533
/**
540534
* Gets the exploration limit for `partialFlow` and `partialFlowRev`
@@ -613,19 +607,11 @@ module DataFlowMake<InputSig Lang> {
613607
/** Gets a textual representation of this element. */
614608
string toString();
615609

616-
/**
617-
* Holds if this element is at the specified location.
618-
* The location spans column `startcolumn` of line `startline` to
619-
* column `endcolumn` of line `endline` in file `filepath`.
620-
* For more information, see
621-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
622-
*/
623-
predicate hasLocationInfo(
624-
string filepath, int startline, int startcolumn, int endline, int endcolumn
625-
);
626-
627610
/** Gets the underlying `Node`. */
628611
Node getNode();
612+
613+
/** Gets the location of this node. */
614+
Location getLocation();
629615
}
630616

631617
signature module PathGraphSig<PathNodeSig PathNode> {
@@ -668,24 +654,26 @@ module DataFlowMake<InputSig Lang> {
668654
result = this.asPathNode2().toString()
669655
}
670656

657+
/** Gets the underlying `Node`. */
658+
Node getNode() {
659+
result = this.asPathNode1().getNode() or
660+
result = this.asPathNode2().getNode()
661+
}
662+
663+
/** Gets the location of this node. */
664+
Location getLocation() { result = this.getNode().getLocation() }
665+
671666
/**
672667
* Holds if this element is at the specified location.
673668
* The location spans column `startcolumn` of line `startline` to
674669
* column `endcolumn` of line `endline` in file `filepath`.
675670
* For more information, see
676671
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
677672
*/
678-
predicate hasLocationInfo(
673+
deprecated predicate hasLocationInfo(
679674
string filepath, int startline, int startcolumn, int endline, int endcolumn
680675
) {
681-
this.asPathNode1().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or
682-
this.asPathNode2().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
683-
}
684-
685-
/** Gets the underlying `Node`. */
686-
Node getNode() {
687-
result = this.asPathNode1().getNode() or
688-
result = this.asPathNode2().getNode()
676+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
689677
}
690678
}
691679

@@ -750,14 +738,17 @@ module DataFlowMake<InputSig Lang> {
750738
* For more information, see
751739
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
752740
*/
753-
predicate hasLocationInfo(
741+
deprecated predicate hasLocationInfo(
754742
string filepath, int startline, int startcolumn, int endline, int endcolumn
755743
) {
756744
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
757745
}
758746

759747
/** Gets the underlying `Node`. */
760748
Node getNode() { result = super.getNode() }
749+
750+
/** Gets the location of this node. */
751+
Location getLocation() { result = super.getLocation() }
761752
}
762753

763754
/**

shared/dataflow/codeql/dataflow/TaintTracking.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
private import DataFlow as DF
77
private import internal.DataFlowImpl
8+
private import codeql.util.Location
89

910
/**
1011
* Provides language-specific taint-tracking parameters.
1112
*/
12-
signature module InputSig<DF::InputSig Lang> {
13+
signature module InputSig<LocationSig Location, DF::InputSig<Location> Lang> {
1314
/**
1415
* Holds if `node` should be a sanitizer in all global taint flow configurations
1516
* but not in local taint.
@@ -33,10 +34,13 @@ signature module InputSig<DF::InputSig Lang> {
3334
/**
3435
* Construct the modules for taint-tracking analyses.
3536
*/
36-
module TaintFlowMake<DF::InputSig DataFlowLang, InputSig<DataFlowLang> TaintTrackingLang> {
37+
module TaintFlowMake<
38+
LocationSig Location, DF::InputSig<Location> DataFlowLang,
39+
InputSig<Location, DataFlowLang> TaintTrackingLang>
40+
{
3741
private import TaintTrackingLang
38-
private import DF::DataFlowMake<DataFlowLang> as DataFlow
39-
private import MakeImpl<DataFlowLang> as DataFlowInternal
42+
private import DF::DataFlowMake<Location, DataFlowLang> as DataFlow
43+
private import MakeImpl<Location, DataFlowLang> as DataFlowInternal
4044

4145
private module AddTaintDefaults<DataFlowInternal::FullStateConfigSig Config> implements
4246
DataFlowInternal::FullStateConfigSig

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

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
private import codeql.util.Unit
88
private import codeql.util.Option
99
private import codeql.util.Boolean
10+
private import codeql.util.Location
1011
private import codeql.dataflow.DataFlow
1112

12-
module MakeImpl<InputSig Lang> {
13+
module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
1314
private import Lang
14-
private import DataFlowMake<Lang>
15-
private import DataFlowImplCommon::MakeImplCommon<Lang>
15+
private import DataFlowMake<Location, Lang>
16+
private import DataFlowImplCommon::MakeImplCommon<Location, Lang>
1617
private import DataFlowImplCommonPublic
1718

1819
/**
@@ -192,11 +193,7 @@ module MakeImpl<InputSig Lang> {
192193
pragma[only_bind_out](this).getDataFlowType0() = pragma[only_bind_into](result)
193194
}
194195

195-
predicate hasLocationInfo(
196-
string filepath, int startline, int startcolumn, int endline, int endcolumn
197-
) {
198-
this.projectToNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
199-
}
196+
Location getLocation() { result = this.projectToNode().getLocation() }
200197
}
201198

202199
private class ArgNodeEx extends NodeEx {
@@ -3305,11 +3302,7 @@ module MakeImpl<InputSig Lang> {
33053302

33063303
override string toString() { result = p + concat(" : " + ppReprType(t)) + " " + ap }
33073304

3308-
predicate hasLocationInfo(
3309-
string filepath, int startline, int startcolumn, int endline, int endcolumn
3310-
) {
3311-
p.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
3312-
}
3305+
Location getLocation() { result = p.getLocation() }
33133306
}
33143307

33153308
/**
@@ -3727,18 +3720,8 @@ module MakeImpl<InputSig Lang> {
37273720
this.ppSummaryCtx()
37283721
}
37293722

3730-
/**
3731-
* Holds if this element is at the specified location.
3732-
* The location spans column `startcolumn` of line `startline` to
3733-
* column `endcolumn` of line `endline` in file `filepath`.
3734-
* For more information, see
3735-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
3736-
*/
3737-
predicate hasLocationInfo(
3738-
string filepath, int startline, int startcolumn, int endline, int endcolumn
3739-
) {
3740-
this.getNodeEx().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
3741-
}
3723+
/** Gets the location of this node. */
3724+
Location getLocation() { result = this.getNodeEx().getLocation() }
37423725
}
37433726

37443727
/** Holds if `n` can reach a sink. */
@@ -3774,17 +3757,21 @@ module MakeImpl<InputSig Lang> {
37743757
*/
37753758
final string toStringWithContext() { result = super.toStringWithContext() }
37763759

3760+
/** Gets the location of this node. */
3761+
Location getLocation() { result = super.getLocation() }
3762+
37773763
/**
37783764
* Holds if this element is at the specified location.
37793765
* The location spans column `startcolumn` of line `startline` to
37803766
* column `endcolumn` of line `endline` in file `filepath`.
37813767
* For more information, see
37823768
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
37833769
*/
3784-
final predicate hasLocationInfo(
3770+
pragma[inline]
3771+
deprecated final predicate hasLocationInfo(
37853772
string filepath, int startline, int startcolumn, int endline, int endcolumn
37863773
) {
3787-
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
3774+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
37883775
}
37893776

37903777
/** Gets the underlying `Node`. */
@@ -3945,12 +3932,6 @@ module MakeImpl<InputSig Lang> {
39453932
override predicate isSource() { none() }
39463933

39473934
override string toString() { result = sourceGroup }
3948-
3949-
override predicate hasLocationInfo(
3950-
string filepath, int startline, int startcolumn, int endline, int endcolumn
3951-
) {
3952-
filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0
3953-
}
39543935
}
39553936

39563937
private class PathNodeSinkGroup extends PathNodeImpl, TPathNodeSinkGroup {
@@ -3967,12 +3948,6 @@ module MakeImpl<InputSig Lang> {
39673948
override predicate isSource() { none() }
39683949

39693950
override string toString() { result = sinkGroup }
3970-
3971-
override predicate hasLocationInfo(
3972-
string filepath, int startline, int startcolumn, int endline, int endcolumn
3973-
) {
3974-
filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0
3975-
}
39763951
}
39773952

39783953
private predicate pathNode(
@@ -4801,17 +4776,21 @@ module MakeImpl<InputSig Lang> {
48014776
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
48024777
}
48034778

4779+
/** Gets the location of this node. */
4780+
Location getLocation() { result = this.getNodeEx().getLocation() }
4781+
48044782
/**
48054783
* Holds if this element is at the specified location.
48064784
* The location spans column `startcolumn` of line `startline` to
48074785
* column `endcolumn` of line `endline` in file `filepath`.
48084786
* For more information, see
48094787
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
48104788
*/
4811-
predicate hasLocationInfo(
4789+
pragma[inline]
4790+
deprecated predicate hasLocationInfo(
48124791
string filepath, int startline, int startcolumn, int endline, int endcolumn
48134792
) {
4814-
this.getNodeEx().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
4793+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
48154794
}
48164795

48174796
/** Gets the underlying `Node`. */

0 commit comments

Comments
 (0)