Skip to content

Data flow: Replace hasLocationInfo with getLocation #15853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 18, 2024
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ import cpp
deprecated module DataFlow {
private import semmle.code.cpp.dataflow.internal.DataFlowImplSpecific
private import codeql.dataflow.DataFlow
import DataFlowMake<CppOldDataFlow>
import DataFlowMake<Location, CppOldDataFlow>
import semmle.code.cpp.dataflow.internal.DataFlowImpl1
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/TaintTracking.qll
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ deprecated module TaintTracking {
private import semmle.code.cpp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.cpp.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.TaintTracking
import TaintFlowMake<CppOldDataFlow, CppOldTaintTracking>
import TaintFlowMake<Location, CppOldDataFlow, CppOldTaintTracking>
import semmle.code.cpp.dataflow.internal.tainttracking1.TaintTrackingImpl
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* DEPRECATED: Use `semmle.code.cpp.dataflow.new.DataFlow` instead.
*/

private import semmle.code.cpp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImpl
import MakeImpl<CppOldDataFlow>
import MakeImpl<Location, CppOldDataFlow>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* DEPRECATED: Use `semmle.code.cpp.dataflow.new.DataFlow` instead.
*/

private import semmle.code.cpp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImplCommon
import MakeImplCommon<CppOldDataFlow>
import MakeImplCommon<Location, CppOldDataFlow>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private import DataFlowImplSpecific
private import TaintTrackingImplSpecific
private import codeql.dataflow.internal.DataFlowImplConsistency

private module Input implements InputSig<CppOldDataFlow> {
private module Input implements InputSig<Location, CppOldDataFlow> {
predicate argHasPostUpdateExclude(Private::ArgumentNode n) {
// Is the null pointer (or something that's not really a pointer)
exists(n.asExpr().getValue())
Expand All @@ -26,4 +26,4 @@ private module Input implements InputSig<CppOldDataFlow> {
}
}

module Consistency = MakeConsistency<CppOldDataFlow, CppOldTaintTracking, Input>;
module Consistency = MakeConsistency<Location, CppOldDataFlow, CppOldTaintTracking, Input>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Provides C++-specific definitions for use in the data flow library.
*/

private import semmle.code.cpp.Location
private import codeql.dataflow.DataFlow

module Private {
Expand All @@ -15,7 +16,7 @@ module Public {
import DataFlowUtil
}

module CppOldDataFlow implements InputSig {
module CppOldDataFlow implements InputSig<Location> {
import Private
import Public

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Node extends TNode {
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
deprecated predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* Provides C++-specific definitions for use in the taint tracking library.
*/

private import semmle.code.cpp.Location
private import codeql.dataflow.TaintTracking
private import DataFlowImplSpecific

module CppOldTaintTracking implements InputSig<CppOldDataFlow> {
module CppOldTaintTracking implements InputSig<Location, CppOldDataFlow> {
import TaintTrackingUtil
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/new/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ import cpp
module DataFlow {
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific
private import codeql.dataflow.DataFlow
import DataFlowMake<CppDataFlow>
import DataFlowMake<Location, CppDataFlow>
import semmle.code.cpp.ir.dataflow.internal.DataFlowImpl1
}
3 changes: 2 additions & 1 deletion cpp/ql/lib/semmle/code/cpp/dataflow/new/TaintTracking.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module TaintTracking {
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific
private import semmle.code.cpp.ir.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.TaintTracking
import TaintFlowMake<CppDataFlow, CppTaintTracking>
private import semmle.code.cpp.Location
import TaintFlowMake<Location, CppDataFlow, CppTaintTracking>
import semmle.code.cpp.ir.dataflow.internal.tainttracking1.TaintTrackingImpl
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/ir/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import cpp
module DataFlow {
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific
private import codeql.dataflow.DataFlow
import DataFlowMake<CppDataFlow>
import DataFlowMake<Location, CppDataFlow>
import semmle.code.cpp.ir.dataflow.internal.DataFlowImpl1
}
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/ir/dataflow/TaintTracking.qll
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ module TaintTracking {
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific
private import semmle.code.cpp.ir.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.TaintTracking
import TaintFlowMake<CppDataFlow, CppTaintTracking>
import TaintFlowMake<Location, CppDataFlow, CppTaintTracking>
import semmle.code.cpp.ir.dataflow.internal.tainttracking1.TaintTrackingImpl
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
private import semmle.code.cpp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImpl
import MakeImpl<CppDataFlow>
import MakeImpl<Location, CppDataFlow>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
private import semmle.code.cpp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImplCommon
import MakeImplCommon<CppDataFlow>
import MakeImplCommon<Location, CppDataFlow>
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ private import DataFlowImplSpecific
private import TaintTrackingImplSpecific
private import codeql.dataflow.internal.DataFlowImplConsistency

private module Input implements InputSig<CppDataFlow> {
private module Input implements InputSig<Location, CppDataFlow> {
predicate argHasPostUpdateExclude(Private::ArgumentNode n) {
// The rules for whether an IR argument gets a post-update node are too
// complex to model here.
any()
}
}

module Consistency = MakeConsistency<CppDataFlow, CppTaintTracking, Input>;
module Consistency = MakeConsistency<Location, CppDataFlow, CppTaintTracking, Input>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

private import codeql.dataflow.DataFlow
private import semmle.code.cpp.Location

module Private {
import DataFlowPrivate
Expand All @@ -13,7 +14,7 @@ module Public {
import DataFlowUtil
}

module CppDataFlow implements InputSig {
module CppDataFlow implements InputSig<Location> {
import Private
import Public

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class Node extends TIRDataFlowNode {
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
deprecated predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

private import codeql.dataflow.TaintTracking
private import DataFlowImplSpecific
private import semmle.code.cpp.Location

module CppTaintTracking implements InputSig<CppDataFlow> {
module CppTaintTracking implements InputSig<Location, CppDataFlow> {
import TaintTrackingUtil
}
4 changes: 2 additions & 2 deletions csharp/ql/consistency-queries/DataFlowConsistency.ql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.internal.DataFlowImplConsistency

private module Input implements InputSig<CsharpDataFlow> {
private module Input implements InputSig<Location, CsharpDataFlow> {
private import CsharpDataFlow

private predicate isStaticAssignable(Assignable a) { a.(Modifiable).isStatic() }
Expand Down Expand Up @@ -99,4 +99,4 @@ private module Input implements InputSig<CsharpDataFlow> {
}
}

import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>
import MakeConsistency<Location, CsharpDataFlow, CsharpTaintTracking, Input>
2 changes: 1 addition & 1 deletion csharp/ql/lib/semmle/code/csharp/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import csharp
module DataFlow {
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
private import codeql.dataflow.DataFlow
import DataFlowMake<CsharpDataFlow>
import DataFlowMake<Location, CsharpDataFlow>
import semmle.code.csharp.dataflow.internal.DataFlowImpl1
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module TaintTracking {
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.TaintTracking
import TaintFlowMake<CsharpDataFlow, CsharpTaintTracking>
import TaintFlowMake<Location, CsharpDataFlow, CsharpTaintTracking>
import semmle.code.csharp.dataflow.internal.tainttracking1.TaintTrackingImpl
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
private import semmle.code.csharp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImpl
import MakeImpl<CsharpDataFlow>
import MakeImpl<Location, CsharpDataFlow>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
private import semmle.code.csharp.Location
private import DataFlowImplSpecific
private import codeql.dataflow.internal.DataFlowImplCommon
import MakeImplCommon<CsharpDataFlow>
import MakeImplCommon<Location, CsharpDataFlow>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Provides C#-specific definitions for use in the data flow library.
*/

private import semmle.code.csharp.Location
private import codeql.dataflow.DataFlow

module Private {
Expand All @@ -13,7 +14,7 @@ module Public {
import DataFlowPublic
}

module CsharpDataFlow implements InputSig {
module CsharpDataFlow implements InputSig<Location> {
import Private
import Public

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Node extends TNode {
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
deprecated predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private import DataFlowImplSpecific::Public
private import semmle.code.csharp.Unification
private import semmle.code.csharp.dataflow.internal.ExternalFlow

module Input implements InputSig<DataFlowImplSpecific::CsharpDataFlow> {
module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow> {
class SummarizedCallableBase = UnboundCallable;

ArgumentPosition callbackSelfParameterPosition() { result.isDelegateSelf() }
Expand Down Expand Up @@ -80,7 +80,7 @@ module Input implements InputSig<DataFlowImplSpecific::CsharpDataFlow> {
}
}

private import Make<DataFlowImplSpecific::CsharpDataFlow, Input> as Impl
private import Make<Location, DataFlowImplSpecific::CsharpDataFlow, Input> as Impl

private module TypesInput implements Impl::Private::TypesInputSig {
DataFlowType getSyntheticGlobalType(Impl::Private::SyntheticGlobal sg) {
Expand Down Expand Up @@ -154,7 +154,7 @@ private module StepsInput implements Impl::Private::StepsInputSig {
}

module SourceSinkInterpretationInput implements
Impl::Private::External::SourceSinkInterpretationInputSig<Location>
Impl::Private::External::SourceSinkInterpretationInputSig
{
private import csharp as Cs

Expand Down Expand Up @@ -252,7 +252,7 @@ module Private {

module External {
import Impl::Private::External
import Impl::Private::External::SourceSinkInterpretation<Location, SourceSinkInterpretationInput>
import Impl::Private::External::SourceSinkInterpretation<SourceSinkInterpretationInput>
}

private module SummaryComponentInternal = Impl::Private::SummaryComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Provides C#-specific definitions for use in the taint tracking library.
*/

private import semmle.code.csharp.Location
private import codeql.dataflow.TaintTracking
private import DataFlowImplSpecific

module CsharpTaintTracking implements InputSig<CsharpDataFlow> {
module CsharpTaintTracking implements InputSig<Location, CsharpDataFlow> {
import TaintTrackingPrivate
}
4 changes: 2 additions & 2 deletions csharp/ql/test/TestUtilities/InlineFlowTest.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
private import internal.InlineExpectationsTestImpl

private module FlowTestImpl implements InputSig<CsharpDataFlow> {
private module FlowTestImpl implements InputSig<Location, CsharpDataFlow> {
predicate defaultSource(DataFlow::Node source) {
source.asExpr().(MethodCall).getTarget().getUndecoratedName() = ["Source", "Taint"]
}
Expand All @@ -35,4 +35,4 @@ private module FlowTestImpl implements InputSig<CsharpDataFlow> {
}
}

import InlineFlowTestMake<CsharpDataFlow, CsharpTaintTracking, Impl, FlowTestImpl>
import InlineFlowTestMake<Location, CsharpDataFlow, CsharpTaintTracking, Impl, FlowTestImpl>
3 changes: 2 additions & 1 deletion go/ql/lib/semmle/go/DiagnosticsReporting.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Provides classes for working with errors and warnings recorded during extraction. */

import go
private import semmle.go.internal.Locations

/** Gets the SARIF severity level that indicates an error. */
private int getErrorSeverity() { result = 2 }
Expand Down Expand Up @@ -29,7 +30,7 @@ private class Diagnostic extends @diagnostic {
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
exists(Location l | diagnostics(this, _, _, _, _, l) | l.hasLocationInfo(path, sl, sc, el, ec))
getDiagnosticLocation(this).hasLocationInfo(path, sl, sc, el, ec)
}

string toString() { result = this.getMessage() }
Expand Down
2 changes: 0 additions & 2 deletions go/ql/lib/semmle/go/Files.qll
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Folder extends Container, Impl::Folder {
class ExtractedOrExternalFile extends Container, Impl::File, Documentable, ExprParent,
GoModExprParent, DeclParent, ScopeNode
{
override Location getLocation() { has_location(this, result) }

/** Gets the number of lines in this file. */
int getNumberOfLines() { numlines(this, result, _, _) }

Expand Down
8 changes: 0 additions & 8 deletions go/ql/lib/semmle/go/HTML.qll
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ module HTML {
class Element extends Locatable, @xmlelement {
Element() { exists(HtmlFile f | xmlElements(this, _, _, _, f)) }

override Location getLocation() { xmllocations(this, result) }

/**
* Gets the name of this HTML element.
*
Expand Down Expand Up @@ -97,8 +95,6 @@ module HTML {
class Attribute extends Locatable, @xmlattribute {
Attribute() { xmlAttrs(this, _, _, _, _, any(HtmlFile f)) }

override Location getLocation() { xmllocations(this, result) }

/**
* Gets the element to which this attribute belongs.
*/
Expand Down Expand Up @@ -180,8 +176,6 @@ module HTML {
* Holds if this text node is inside a `CDATA` tag.
*/
predicate isCData() { xmlChars(this, _, _, _, 1, _) }

override Location getLocation() { xmllocations(this, result) }
}

/**
Expand All @@ -203,7 +197,5 @@ module HTML {
string getText() { result = this.toString().regexpCapture("(?s)<!--(.*)-->", 1) }

override string toString() { xmlComments(this, result, _, _) }

override Location getLocation() { xmllocations(this, result) }
}
}
Loading