From ca0b363be3f6950b26cee773e06329fbd6001261 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 26 Feb 2025 15:00:56 +0000 Subject: [PATCH 1/3] Replace DbLocation with Location --- go/ql/lib/semmle/go/DiagnosticsReporting.qll | 5 +- go/ql/lib/semmle/go/Locations.qll | 23 ++- go/ql/lib/semmle/go/internal/Locations.qll | 150 ------------------ .../diagnostics/Diagnostics.ql | 8 +- .../library-tests/semmle/go/Types/Aliases.ql | 2 +- 5 files changed, 16 insertions(+), 172 deletions(-) delete mode 100644 go/ql/lib/semmle/go/internal/Locations.qll diff --git a/go/ql/lib/semmle/go/DiagnosticsReporting.qll b/go/ql/lib/semmle/go/DiagnosticsReporting.qll index e05fe0e7a58a..424f8a71ef46 100644 --- a/go/ql/lib/semmle/go/DiagnosticsReporting.qll +++ b/go/ql/lib/semmle/go/DiagnosticsReporting.qll @@ -1,7 +1,6 @@ /** 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 } @@ -30,7 +29,9 @@ 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) { - getDiagnosticLocation(this).hasLocationInfo(path, sl, sc, el, ec) + exists(Location loc | diagnostics(this, _, _, _, _, loc) | + loc.hasLocationInfo(path, sl, sc, el, ec) + ) } string toString() { result = this.getMessage() } diff --git a/go/ql/lib/semmle/go/Locations.qll b/go/ql/lib/semmle/go/Locations.qll index d5ab0858f213..817fea56f007 100644 --- a/go/ql/lib/semmle/go/Locations.qll +++ b/go/ql/lib/semmle/go/Locations.qll @@ -1,7 +1,6 @@ /** Provides classes for working with locations and program elements that have locations. */ import go -private import internal.Locations /** * A location as given by a file, a start line, a start column, @@ -11,21 +10,21 @@ private import internal.Locations * * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). */ -class DbLocation extends TDbLocation { +class Location extends @location { /** Gets the file for this location. */ - File getFile() { dbLocationInfo(this, result, _, _, _, _) } + File getFile() { locations_default(this, result, _, _, _, _) } /** Gets the 1-based line number (inclusive) where this location starts. */ - int getStartLine() { dbLocationInfo(this, _, result, _, _, _) } + int getStartLine() { locations_default(this, _, result, _, _, _) } /** Gets the 1-based column number (inclusive) where this location starts. */ - int getStartColumn() { dbLocationInfo(this, _, _, result, _, _) } + int getStartColumn() { locations_default(this, _, _, result, _, _) } /** Gets the 1-based line number (inclusive) where this location ends. */ - int getEndLine() { dbLocationInfo(this, _, _, _, result, _) } + int getEndLine() { locations_default(this, _, _, _, result, _) } /** Gets the 1-based column number (inclusive) where this location ends. */ - int getEndColumn() { dbLocationInfo(this, _, _, _, _, result) } + int getEndColumn() { locations_default(this, _, _, _, _, result) } /** Gets the number of lines covered by this location. */ int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 } @@ -48,22 +47,22 @@ class DbLocation extends TDbLocation { predicate hasLocationInfo( string filepath, int startline, int startcolumn, int endline, int endcolumn ) { - exists(File f | - dbLocationInfo(this, f, startline, startcolumn, endline, endcolumn) and + exists(File f | locations_default(this, f, startline, startcolumn, endline, endcolumn) | filepath = f.getAbsolutePath() ) } } -final class Location = LocationImpl; - /** A program element with a location. */ class Locatable extends @locatable { /** Gets the file this program element comes from. */ File getFile() { result = this.getLocation().getFile() } /** Gets this element's location. */ - final DbLocation getLocation() { result = getLocatableLocation(this) } + final Location getLocation() { + has_location(this, result) or + xmllocations(this, result) + } /** Gets the number of lines covered by this element. */ int getNumLines() { result = this.getLocation().getNumLines() } diff --git a/go/ql/lib/semmle/go/internal/Locations.qll b/go/ql/lib/semmle/go/internal/Locations.qll deleted file mode 100644 index 8b0a206b8838..000000000000 --- a/go/ql/lib/semmle/go/internal/Locations.qll +++ /dev/null @@ -1,150 +0,0 @@ -/** Provides classes for working with locations and program elements that have locations. */ - -import go - -// Should _not_ be cached, as that would require the data flow stage to be evaluated -// in order to evaluate the AST stage. Ideally, we would cache each injector separately, -// but that's not possible. Instead, we cache all predicates that need the injectors -// to be tuple numbered. -newtype TLocation = - TDbLocation(@location loc) or - TSynthLocation(string filepath, int startline, int startcolumn, int endline, int endcolumn) { - any(DataFlow::Node n).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - // avoid overlap with existing DB locations - not existingDBLocation(filepath, startline, startcolumn, endline, endcolumn) - } - -pragma[nomagic] -private predicate existingDBLocation( - string filepath, int startline, int startcolumn, int endline, int endcolumn -) { - exists(File f | - locations_default(_, f, startline, startcolumn, endline, endcolumn) and - f.getAbsolutePath() = filepath - ) -} - -/** - * A location as given by a file, a start line, a start column, - * an end line, and an end column. - * - * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). - */ -abstract class LocationImpl extends TLocation { - /** Gets the file for this location. */ - abstract File getFile(); - - /** Gets the 1-based line number (inclusive) where this location starts. */ - abstract int getStartLine(); - - /** Gets the 1-based column number (inclusive) where this location starts. */ - abstract int getStartColumn(); - - /** Gets the 1-based line number (inclusive) where this location ends. */ - abstract int getEndLine(); - - /** Gets the 1-based column number (inclusive) where this location ends. */ - abstract int getEndColumn(); - - /** Gets the number of lines covered by this location. */ - int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 } - - /** Gets a textual representation of this element. */ - string toString() { - exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | - this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn - ) - } - - /** - * Holds if this element is at the specified location. - * The location spans column `startcolumn` of line `startline` to - * column `endcolumn` of line `endline` in file `filepath`. - * For more information, see - * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). - */ - abstract predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ); -} - -class DbLocationImpl extends LocationImpl instanceof DbLocation { - private @location loc; - - DbLocationImpl() { this = TDbLocation(loc) } - - override File getFile() { result = DbLocation.super.getFile() } - - override int getStartLine() { result = DbLocation.super.getStartLine() } - - override int getStartColumn() { result = DbLocation.super.getStartColumn() } - - override int getEndLine() { result = DbLocation.super.getEndLine() } - - override int getEndColumn() { result = DbLocation.super.getEndColumn() } - - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - DbLocation.super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } -} - -class SynthLocationImpl extends LocationImpl, TSynthLocation { - override File getFile() { synthLocationInfo(this, result.getAbsolutePath(), _, _, _, _) } - - override int getStartLine() { synthLocationInfo(this, _, result, _, _, _) } - - override int getStartColumn() { synthLocationInfo(this, _, _, result, _, _) } - - override int getEndLine() { synthLocationInfo(this, _, _, _, result, _) } - - override int getEndColumn() { synthLocationInfo(this, _, _, _, _, result) } - - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - synthLocationInfo(this, filepath, startline, startcolumn, endline, endcolumn) - } -} - -cached -private module Cached { - cached - DbLocation getLocatableLocation(@locatable l) { - exists(@location loc | - has_location(l, loc) or - xmllocations(l, loc) - | - result = TDbLocation(loc) - ) - } - - cached - DbLocation getDiagnosticLocation(@diagnostic d) { - exists(@location loc | - diagnostics(d, _, _, _, _, loc) and - result = TDbLocation(loc) - ) - } - - cached - predicate dbLocationInfo( - DbLocation l, File f, int startline, int startcolumn, int endline, int endcolumn - ) { - exists(@location loc | - l = TDbLocation(loc) and - locations_default(loc, f, startline, startcolumn, endline, endcolumn) - ) - } -} - -import Cached - -cached -private predicate synthLocationInfo( - SynthLocationImpl l, string filepath, int startline, int startcolumn, int endline, int endcolumn -) { - l = TSynthLocation(filepath, startline, startcolumn, endline, endcolumn) -} diff --git a/go/ql/test/extractor-tests/diagnostics/Diagnostics.ql b/go/ql/test/extractor-tests/diagnostics/Diagnostics.ql index 324709175e5c..ed6d8ac043de 100644 --- a/go/ql/test/extractor-tests/diagnostics/Diagnostics.ql +++ b/go/ql/test/extractor-tests/diagnostics/Diagnostics.ql @@ -1,5 +1,4 @@ import go -private import semmle.go.internal.Locations bindingset[path] string baseName(string path) { result = path.regexpCapture(".*(/|\\\\)([^/\\\\]+)(/|\\\\)?$", 2) } @@ -31,12 +30,7 @@ class Diagnostic extends @diagnostic { diagnostic_for(this, c, fileNum, idx) } - DbLocation getLocation() { - exists(@location loc | - diagnostics(this, _, _, _, _, loc) and - result = TDbLocation(loc) - ) - } + Location getLocation() { diagnostics(this, _, _, _, _, result) } // string getTag() { // diagnostics(this, _, result, _, _, _) diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql index 79f366e37d94..d4c15358f06c 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql @@ -5,7 +5,7 @@ int countDecls(Entity e) { result = count(Ident decl | decl = e.getDeclaration() query predicate entities(string fp, Entity e, int c, Type ty) { c = countDecls(e) and ty = e.getType() and - exists(DbLocation loc | + exists(Location loc | loc = e.getDeclaration().getLocation() and fp = loc.getFile().getBaseName() and fp = "aliases.go" From f322cb7968ff0b78fcfd62847a63c34d90d307ac Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 27 Feb 2025 11:51:56 +0000 Subject: [PATCH 2/3] Use `getLocation` instead of `hasLocationInfo` --- go/ql/lib/semmle/go/DiagnosticsReporting.qll | 18 +- go/ql/lib/semmle/go/Scopes.qll | 48 ++-- go/ql/lib/semmle/go/StringOps.qll | 11 +- go/ql/lib/semmle/go/Types.qll | 11 +- go/ql/lib/semmle/go/VariableWithFields.qll | 9 +- .../lib/semmle/go/controlflow/BasicBlocks.qll | 9 +- .../go/controlflow/ControlFlowGraph.qll | 18 +- .../go/controlflow/ControlFlowGraphImpl.qll | 18 +- go/ql/lib/semmle/go/controlflow/IR.qll | 228 ++++-------------- .../go/dataflow/GlobalValueNumbering.qll | 13 +- go/ql/lib/semmle/go/dataflow/SSA.qll | 61 ++--- .../go/dataflow/internal/DataFlowNodes.qll | 65 ++--- .../go/dataflow/internal/DataFlowPrivate.qll | 30 +-- .../go/dataflow/internal/DataFlowUtil.qll | 37 ++- .../go/dataflow/internal/FlowSummaryImpl.qll | 36 +-- go/ql/lib/semmle/go/frameworks/GoMicro.qll | 12 +- go/ql/lib/semmle/go/frameworks/Twirp.qll | 14 +- .../go/frameworks/stdlib/HtmlTemplate.qll | 41 ++-- .../WhitespaceContradictsPrecedence.ql | 11 +- .../DecompressionBombTest.ql | 3 +- .../frameworks/CleverGo/HeaderWrite.ql | 9 +- .../frameworks/CleverGo/HttpRedirect.ql | 3 +- .../frameworks/CleverGo/HttpResponseBody.ql | 3 +- .../frameworks/CleverGo/RemoteSources.ql | 3 +- .../frameworks/Fiber/HeaderWrite.ql | 9 +- .../experimental/frameworks/Fiber/Redirect.ql | 3 +- .../frameworks/Fiber/RemoteFlowSources.ql | 3 +- .../frameworks/Fiber/ResponseBody.ql | 3 +- .../semmle/go/Function/TypeParamType.ql | 2 +- .../semmle/go/Function/isVariadic.ql | 3 +- .../semmle/go/GoModExpr/GoModExprs.ql | 24 +- .../library-tests/semmle/go/Types/Aliases.ql | 7 +- .../semmle/go/Types/ImplementsComparable.ql | 3 +- .../go/Types/SignatureType_isVariadic.ql | 3 +- .../semmle/go/aliases/MethodDefs/test.ql | 6 +- .../semmle/go/aliases/defsuses/test.ql | 6 +- .../semmle/go/concepts/HTTP/Handler.ql | 3 +- .../go/concepts/LoggerCall/LoggerCall.ql | 3 +- .../go/dataflow/CallGraph/getACallee.ql | 6 +- .../go/dataflow/CallGraph/viableCallee.ql | 6 +- .../mad_I1_subtypes_false.ql | 3 +- .../mad_I1_subtypes_true.ql | 3 +- .../mad_I2_subtypes_false.ql | 3 +- .../mad_I2_subtypes_true.ql | 3 +- .../mad_IEmbedI1_subtypes_true.ql | 3 +- .../mad_IEmbedI2_subtypes_true.ql | 3 +- .../mad_PImplEmbedI1_subtypes_true.ql | 3 +- .../mad_PImplEmbedI2_subtypes_true.ql | 3 +- .../mad_S1_subtypes_false.ql | 3 +- .../mad_S1_subtypes_true.ql | 3 +- .../mad_SEmbedI1_subtypes_true.ql | 3 +- .../mad_SEmbedI2_subtypes_true.ql | 3 +- .../mad_SEmbedP1_subtypes_true.ql | 3 +- .../mad_SEmbedP2_subtypes_true.ql | 3 +- .../mad_SEmbedPtrP1_subtypes_true.ql | 3 +- .../mad_SEmbedPtrP2_subtypes_true.ql | 3 +- .../mad_SEmbedPtrS1_subtypes_true.ql | 3 +- .../mad_SEmbedPtrS2_subtypes_true.ql | 3 +- .../mad_SEmbedS1_subtypes_true.ql | 3 +- .../mad_SEmbedS2_subtypes_true.ql | 3 +- .../mad_SImplEmbedI1_subtypes_true.ql | 3 +- .../mad_SImplEmbedI2_subtypes_true.ql | 3 +- .../mad_SImplEmbedS1_subtypes_true.ql | 3 +- .../mad_SImplEmbedS2_subtypes_true.ql | 3 +- .../dataflow/ExternalFlowInheritance/ql_I1.ql | 3 +- .../dataflow/ExternalFlowInheritance/ql_P1.ql | 3 +- .../dataflow/ExternalFlowInheritance/ql_S1.ql | 3 +- .../PromotedMethods/DataFlowConfig.ql | 3 +- .../flowsources/local/commandargs/test.ql | 3 +- .../flowsources/local/database/source.ql | 3 +- .../flowsources/local/environment/test.ql | 3 +- .../dataflow/flowsources/local/file/test.ql | 3 +- .../flowsources/local/stdin/source.ql | 3 +- .../semmle/go/frameworks/Afero/Query.ql | 9 +- .../go/frameworks/BeegoOrm/QueryString.ql | 10 +- .../semmle/go/frameworks/CouchbaseV1/test.ql | 3 +- .../go/frameworks/ElazarlGoproxy/test.ql | 13 +- .../go/frameworks/Fasthttp/EscapeFunction.ql | 3 +- .../frameworks/Fasthttp/FileSystemAccess.ql | 4 +- .../go/frameworks/Fasthttp/OpenRedirect.ql | 3 +- .../frameworks/Fasthttp/RemoteFlowSources.ql | 4 +- .../semmle/go/frameworks/Fasthttp/SSRF.ql | 4 +- .../semmle/go/frameworks/Fasthttp/Xss.ql | 4 +- .../semmle/go/frameworks/Fiber/Query.ql | 3 +- .../go/frameworks/GoKit/RemoteFlowSources.ql | 4 +- .../semmle/go/frameworks/GoMicro/gomicro.ql | 3 +- .../semmle/go/frameworks/Iris/Query.ql | 3 +- .../K8sIoClientGo/SecretInterfaceSource.ql | 4 +- .../semmle/go/frameworks/Macaron/Sources.ql | 3 +- .../semmle/go/frameworks/NoSQL/Query.ql | 3 +- .../semmle/go/frameworks/Revel/test.ql | 6 +- .../go/frameworks/SQL/Gorm/QueryString.ql | 10 +- .../semmle/go/frameworks/SQL/QueryString.ql | 10 +- .../go/frameworks/SQL/Sqlx/QueryString.ql | 10 +- .../go/frameworks/SQL/bun/QueryString.ql | 10 +- .../go/frameworks/SQL/gogf/QueryString.ql | 10 +- .../go/frameworks/SQL/gorqlite/QueryString.ql | 10 +- .../go/frameworks/StdlibTaintFlow/test.ql | 3 +- .../semmle/go/frameworks/Yaml/tests.ql | 12 +- .../semmle/go/frameworks/gqlgen/gqlgen.ql | 3 +- .../CWE-681/IncorrectIntegerConversion.ql | 3 +- 101 files changed, 413 insertions(+), 654 deletions(-) diff --git a/go/ql/lib/semmle/go/DiagnosticsReporting.qll b/go/ql/lib/semmle/go/DiagnosticsReporting.qll index 424f8a71ef46..691c430aa73e 100644 --- a/go/ql/lib/semmle/go/DiagnosticsReporting.qll +++ b/go/ql/lib/semmle/go/DiagnosticsReporting.qll @@ -19,20 +19,10 @@ private class Diagnostic extends @diagnostic { string getMessage() { diagnostics(this, _, _, result, _, _) } /** Gets the file that this error is associated with, if any. */ - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } + File getFile() { result = this.getLocation().getFile() } - /** - * Holds if this element is at the specified location. - * The location spans column `startcolumn` of line `startline` to - * column `endcolumn` of line `endline` in file `filepath`. - * For more information, see - * [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 loc | diagnostics(this, _, _, _, _, loc) | - loc.hasLocationInfo(path, sl, sc, el, ec) - ) - } + /** Gets the location for this error. */ + Location getLocation() { diagnostics(this, _, _, _, _, result) } string toString() { result = this.getMessage() } } @@ -69,7 +59,7 @@ predicate reportableDiagnostics(Diagnostic d, string msg, int sev) { exists(File f | f = d.getFile() | exists(f.getAChild()) and msg = - "Extraction failed in " + d.getFile().getRelativePath() + " with error " + + "Extraction failed in " + f.getRelativePath() + " with error " + removeAbsolutePaths(d.getMessage()) ) or diff --git a/go/ql/lib/semmle/go/Scopes.qll b/go/ql/lib/semmle/go/Scopes.qll index edea24c184fc..82b4db7e3221 100644 --- a/go/ql/lib/semmle/go/Scopes.qll +++ b/go/ql/lib/semmle/go/Scopes.qll @@ -144,36 +144,34 @@ class Entity extends @object { /** Gets a textual representation of this entity. */ string toString() { result = this.getName() } - private predicate hasRealLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - // take the location of the declaration if there is one - this.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or - any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable()) - .hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + /** Gets the location of this entity. */ + Location getLocation() { + result = this.getDeclaration().getLocation() + or + result = any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable()).getLocation() } /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - // take the location of the declaration if there is one - if this.hasRealLocationInfo(_, _, _, _, _) - then this.hasRealLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - else ( - // otherwise fall back on dummy location - filepath = "" and - startline = 0 and - startcolumn = 0 and - endline = 0 and - endcolumn = 0 - ) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + or + // otherwise fall back on dummy location + not exists(this.getLocation()) and + filepath = "" and + startline = 0 and + startcolumn = 0 and + endline = 0 and + endcolumn = 0 } } @@ -680,16 +678,22 @@ class Callable extends TCallable { result = this.asFuncLit().getName() } + /** Gets the location of this callable. */ + Location getLocation() { + result = this.asFunction().getLocation() or result = this.asFuncLit().getLocation() + } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `sc` of line `sl` to * column `ec` of line `el` in file `fp`. * For more information, see * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). */ - predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { - this.asFunction().hasLocationInfo(fp, sl, sc, el, ec) or - this.asFuncLit().hasLocationInfo(fp, sl, sc, el, ec) + deprecated predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { + this.getLocation().hasLocationInfo(fp, sl, sc, el, ec) } } diff --git a/go/ql/lib/semmle/go/StringOps.qll b/go/ql/lib/semmle/go/StringOps.qll index ac779fe3e965..351617abf9de 100644 --- a/go/ql/lib/semmle/go/StringOps.qll +++ b/go/ql/lib/semmle/go/StringOps.qll @@ -548,20 +548,25 @@ module StringOps { else result = "concatenation element" } + /** Gets the location of this element. */ + Location getLocation() { result = this.asNode().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.asNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or // use dummy location for elements that don't have a corresponding node - not exists(this.asNode()) and + not exists(this.getLocation()) and filepath = "" and startline = 0 and startcolumn = 0 and diff --git a/go/ql/lib/semmle/go/Types.qll b/go/ql/lib/semmle/go/Types.qll index 4eb3a3e03029..d6765f136628 100644 --- a/go/ql/lib/semmle/go/Types.qll +++ b/go/ql/lib/semmle/go/Types.qll @@ -144,19 +144,24 @@ class Type extends @type { */ string toString() { result = this.getName() } + /** Gets the location of this type. */ + Location getLocation() { result = this.getEntity().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.getEntity().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or - not exists(this.getEntity()) and + not exists(this.getLocation()) and filepath = "" and startline = 0 and startcolumn = 0 and diff --git a/go/ql/lib/semmle/go/VariableWithFields.qll b/go/ql/lib/semmle/go/VariableWithFields.qll index adb5e2b308a7..0fce5247dcd3 100644 --- a/go/ql/lib/semmle/go/VariableWithFields.qll +++ b/go/ql/lib/semmle/go/VariableWithFields.qll @@ -183,16 +183,21 @@ class VariableWithFields extends TVariableWithFields { */ string getElement() { this = TVariableElementStep(_, result) } + /** Gets the location of this variable with fields. */ + Location getLocation() { result = this.getBaseVariable().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.getBaseVariable().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } diff --git a/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll b/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll index 22484117242a..8380c6d6d5d2 100644 --- a/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll +++ b/go/ql/lib/semmle/go/controlflow/BasicBlocks.qll @@ -114,17 +114,22 @@ class BasicBlock extends TControlFlowNode { /** Gets a textual representation of this basic block. */ string toString() { result = "basic block" } + /** Gets the source location for this element. */ + Location getLocation() { result = this.getFirstNode().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this basic block is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.getFirstNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } diff --git a/go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll b/go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll index 6bbdbd989603..f5905b89beac 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll @@ -77,23 +77,31 @@ module ControlFlow { Root getRoot() { none() } /** Gets the file to which this node belongs. */ - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } + File getFile() { result = this.getLocation().getFile() } /** * Gets a textual representation of this control flow node. */ string toString() { result = "control-flow node" } + /** Gets the source location for this element. */ + Location getLocation() { none() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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) + or + not exists(this.getLocation()) and filepath = "" and startline = 0 and startcolumn = 0 and @@ -244,11 +252,7 @@ module ControlFlow { override string toString() { result = cond + " is " + outcome } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - cond.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = cond.getLocation() } } /** diff --git a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll index 4ca790a2cdd8..71bd0ea561f1 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -418,11 +418,7 @@ class SkipNode extends ControlFlow::Node, MkSkipNode { override string toString() { result = "skip" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - skip.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = skip.getLocation() } } /** @@ -437,11 +433,7 @@ class EntryNode extends ControlFlow::Node, MkEntryNode { override string toString() { result = "entry" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = root.getLocation() } } /** @@ -456,11 +448,7 @@ class ExitNode extends ControlFlow::Node, MkExitNode { override string toString() { result = "exit" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - root.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = root.getLocation() } } /** diff --git a/go/ql/lib/semmle/go/controlflow/IR.qll b/go/ql/lib/semmle/go/controlflow/IR.qll index c401b661643f..6c7a0c682b53 100644 --- a/go/ql/lib/semmle/go/controlflow/IR.qll +++ b/go/ql/lib/semmle/go/controlflow/IR.qll @@ -218,11 +218,7 @@ module IR { override string toString() { result = e.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = e.getLocation() } } /** @@ -364,11 +360,7 @@ module IR { override string toString() { result = "implicit read of field " + field.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - e.getBase().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = e.getBase().getLocation() } } /** @@ -483,11 +475,7 @@ module IR { override string toString() { result = "init of " + elt } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - elt.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = elt.getLocation() } } /** @@ -644,11 +632,7 @@ module IR { override string toString() { result = "element index" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - elt.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = elt.getLocation() } } /** @@ -682,11 +666,7 @@ module IR { override string toString() { result = "assignment to " + this.getLhs() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - this.getLhs().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = this.getLhs().getLocation() } } /** An instruction computing the value of the right-hand side of a compound assignment. */ @@ -704,11 +684,7 @@ module IR { override string toString() { result = assgn.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - assgn.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = assgn.getLocation() } } /** @@ -792,11 +768,7 @@ module IR { override string toString() { result = s + "[" + i + "]" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - s.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = s.getLocation() } } /** @@ -840,11 +812,7 @@ module IR { override string toString() { result = "zero value for " + v } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - v.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = v.getDeclaration().getLocation() } } /** @@ -859,11 +827,7 @@ module IR { override string toString() { result = fd.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - fd.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = fd.getLocation() } } /** @@ -878,11 +842,7 @@ module IR { override string toString() { result = defer.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - defer.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = defer.getLocation() } } /** @@ -897,11 +857,7 @@ module IR { override string toString() { result = go.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - go.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = go.getLocation() } } /** @@ -918,11 +874,7 @@ module IR { override string toString() { result = ids.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ids.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ids.getLocation() } } /** @@ -943,11 +895,7 @@ module IR { override string toString() { result = "rhs of " + ids } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ids.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ids.getLocation() } } /** @@ -975,11 +923,7 @@ module IR { override string toString() { result = "1" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ids.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ids.getLocation() } } /** @@ -1014,11 +958,7 @@ module IR { override string toString() { result = ret.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ret.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ret.getLocation() } } /** @@ -1048,11 +988,7 @@ module IR { override string toString() { result = "implicit write of " + var } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ret.getResult(i).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ret.getResult(i).getLocation() } } /** @@ -1072,11 +1008,7 @@ module IR { override string toString() { result = "implicit read of " + var } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - var.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = var.getDeclaration().getLocation() } } /** @@ -1091,11 +1023,7 @@ module IR { override string toString() { result = sel.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - sel.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = sel.getLocation() } } /** @@ -1110,11 +1038,7 @@ module IR { override string toString() { result = send.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - send.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = send.getLocation() } } /** @@ -1131,11 +1055,7 @@ module IR { override string toString() { result = "initialization of " + parm } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - parm.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = parm.getDeclaration().getLocation() } } /** @@ -1152,11 +1072,7 @@ module IR { override string toString() { result = "argument corresponding to " + parm } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - parm.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = parm.getDeclaration().getLocation() } } /** @@ -1173,11 +1089,7 @@ module IR { override string toString() { result = "initialization of " + res } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - res.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = res.getDeclaration().getLocation() } } /** @@ -1197,11 +1109,7 @@ module IR { override string toString() { result = "next key-value pair in range" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - rs.getDomain().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = rs.getDomain().getLocation() } } /** @@ -1226,11 +1134,7 @@ module IR { override string toString() { result = "true" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - stmt.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = stmt.getLocation() } } /** @@ -1259,11 +1163,7 @@ module IR { override string toString() { result = "case " + cc.getExpr(i) } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - cc.getExpr(i).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = cc.getExpr(i).getLocation() } } /** @@ -1305,11 +1205,7 @@ module IR { override string toString() { result = "implicit type switch variable declaration" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - cc.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = cc.getLocation() } } /** @@ -1335,11 +1231,7 @@ module IR { override string toString() { result = "0" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - slice.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = slice.getLocation() } } /** @@ -1357,11 +1249,7 @@ module IR { override string toString() { result = "len" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - slice.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = slice.getLocation() } } /** @@ -1379,11 +1267,7 @@ module IR { override string toString() { result = "cap" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - slice.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = slice.getLocation() } } /** @@ -1406,11 +1290,7 @@ module IR { override string toString() { result = "implicit dereference" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = e.getLocation() } } /** A representation of the target of a write instruction. */ @@ -1438,17 +1318,29 @@ module IR { /** Gets a textual representation of this target. */ string toString() { result = "write target" } + /** Gets the source location for this element. */ + Location getLocation() { none() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0 + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + or + not exists(this.getLocation()) and + filepath = "" and + startline = 0 and + startcolumn = 0 and + endline = 0 and + endcolumn = 0 } } @@ -1501,11 +1393,7 @@ module IR { override string toString() { result = this.getName() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - loc.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = loc.getLocation() } } /** A reference to a field, used as the target of a write. */ @@ -1545,14 +1433,10 @@ module IR { result = "field " + w.(InitLiteralStructFieldInstruction).getFieldName() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - exists(SelectorExpr sel | this = MkLhs(_, sel) | - sel.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - ) + override Location getLocation() { + exists(SelectorExpr sel | this = MkLhs(_, sel) | result = sel.getLocation()) or - w.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + result = w.(InitLiteralStructFieldInstruction).getLocation() } } @@ -1582,14 +1466,10 @@ module IR { override string toString() { result = "element" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - exists(IndexExpr idx | this = MkLhs(_, idx) | - idx.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - ) + override Location getLocation() { + exists(IndexExpr idx | this = MkLhs(_, idx) | result = idx.getLocation()) or - w.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + result = w.(InitLiteralElementInstruction).getLocation() } } @@ -1613,11 +1493,7 @@ module IR { override string toString() { result = lhs.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - lhs.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = lhs.getLocation() } } /** diff --git a/go/ql/lib/semmle/go/dataflow/GlobalValueNumbering.qll b/go/ql/lib/semmle/go/dataflow/GlobalValueNumbering.qll index 6dcbabc65bb7..ba3a3c733023 100644 --- a/go/ql/lib/semmle/go/dataflow/GlobalValueNumbering.qll +++ b/go/ql/lib/semmle/go/dataflow/GlobalValueNumbering.qll @@ -300,7 +300,9 @@ class GVN extends GvnBase { // just an arbitrary way to pick an expression with this `GVN`. result = min(DataFlow::Node e, string f, int l, int c, string k | - e = this.getANode() and e.hasLocationInfo(f, l, c, _, _) and k = e.getNodeKind() + e = this.getANode() and + e.getLocation().hasLocationInfo(f, l, c, _, _) and + k = e.getNodeKind() | e order by f, l, c, k ) @@ -309,17 +311,22 @@ class GVN extends GvnBase { /** Gets a textual representation of this element. */ string toString() { result = this.exampleNode().toString() } + /** Gets the location of this element. */ + Location getLocation() { result = this.exampleNode().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.exampleNode().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } diff --git a/go/ql/lib/semmle/go/dataflow/SSA.qll b/go/ql/lib/semmle/go/dataflow/SSA.qll index ae0d267cace6..d13bbe2de63a 100644 --- a/go/ql/lib/semmle/go/dataflow/SSA.qll +++ b/go/ql/lib/semmle/go/dataflow/SSA.qll @@ -85,17 +85,22 @@ class SsaVariable extends TSsaDefinition { /** Gets a textual representation of this element. */ string toString() { result = this.getDefinition().prettyPrintRef() } + /** Gets the location of this SSA variable. */ + Location getLocation() { result = this.getDefinition().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.getDefinition().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } @@ -144,16 +149,23 @@ class SsaDefinition extends TSsaDefinition { /** Gets a textual representation of this element. */ string toString() { result = this.prettyPrintDef() } + /** Gets the source location for this element. */ + abstract Location getLocation(); + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * For more information, see * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). */ - abstract predicate hasLocationInfo( + deprecated predicate hasLocationInfo( string filepath, int startline, int startcolumn, int endline, int endcolumn - ); + ) { + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + } } /** @@ -177,16 +189,14 @@ class SsaExplicitDefinition extends SsaDefinition, TExplicitDef { override SsaSourceVariable getSourceVariable() { this = TExplicitDef(_, _, result) } override string prettyPrintRef() { - exists(int l, int c | this.hasLocationInfo(_, l, c, _, _) | result = "def@" + l + ":" + c) + exists(Location loc | loc = this.getLocation() | + result = "def@" + loc.getStartLine() + ":" + loc.getStartColumn() + ) } override string prettyPrintDef() { result = "definition of " + this.getSourceVariable() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - this.getInstruction().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = this.getInstruction().getLocation() } } /** Provides a helper predicate for working with explicit SSA definitions. */ @@ -209,16 +219,12 @@ abstract class SsaImplicitDefinition extends SsaDefinition { abstract string getKind(); override string prettyPrintRef() { - exists(int l, int c | this.hasLocationInfo(_, l, c, _, _) | - result = this.getKind() + "@" + l + ":" + c + exists(Location loc | loc = this.getLocation() | + result = this.getKind() + "@" + loc.getStartLine() + ":" + loc.getStartColumn() ) } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - this.getBasicBlock().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = this.getBasicBlock().getLocation() } } /** @@ -241,11 +247,9 @@ class SsaVariableCapture extends SsaImplicitDefinition, TCapture { override string prettyPrintDef() { result = "capture variable " + this.getSourceVariable() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { + override Location getLocation() { exists(ReachableBasicBlock bb, int i | this.definesAt(bb, i, _) | - bb.getNode(i).hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + result = bb.getNode(i).getLocation() ) } } @@ -291,11 +295,7 @@ class SsaPhiNode extends SsaPseudoDefinition, TPhi { result = this.getSourceVariable() + " = phi(" + this.ppInputs() + ")" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - this.getBasicBlock().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = this.getBasicBlock().getLocation() } } /** @@ -383,17 +383,22 @@ class SsaWithFields extends TSsaWithFields { ) } + /** Gets the location of this SSA variable with fields. */ + Location getLocation() { result = this.getBaseVariable().getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.getBaseVariable().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } diff --git a/go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll b/go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll index cc353ab64df5..a770f047d651 100644 --- a/go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll +++ b/go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll @@ -78,9 +78,7 @@ module Private { result = this.getSummaryNode().getSummarizedCallable() } - override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { - this.getSummarizedCallable().hasLocationInfo(fp, sl, sc, el, ec) - } + override Location getLocation() { result = this.getSummarizedCallable().getLocation() } override string toString() { result = this.getSummaryNode().toString() } @@ -140,45 +138,38 @@ module Public { /** Gets a textual representation of this element. */ string toString() { result = "data-flow node" } // overridden in subclasses + /** Gets the location of this node. */ + Location getLocation() { none() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - filepath = "" and - startline = 0 and - startcolumn = 0 and - endline = 0 and - endcolumn = 0 - } - - /** Gets the location of this node. */ - Location getLocation() { - exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | - this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - ) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } /** Gets the file in which this node appears. */ - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } + File getFile() { result = this.getLocation().getFile() } /** Gets the start line of the location of this node. */ - int getStartLine() { this.hasLocationInfo(_, result, _, _, _) } + int getStartLine() { result = this.getLocation().getStartLine() } /** Gets the start column of the location of this node. */ - int getStartColumn() { this.hasLocationInfo(_, _, result, _, _) } + int getStartColumn() { result = this.getLocation().getStartColumn() } /** Gets the end line of the location of this node. */ - int getEndLine() { this.hasLocationInfo(_, _, _, result, _) } + int getEndLine() { result = this.getLocation().getEndLine() } /** Gets the end column of the location of this node. */ - int getEndColumn() { this.hasLocationInfo(_, _, _, _, result) } + int getEndColumn() { result = this.getLocation().getEndColumn() } /** * Gets an upper bound on the type of this node. @@ -262,11 +253,7 @@ module Public { override string toString() { result = insn.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - insn.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = insn.getLocation() } } /** @@ -312,11 +299,7 @@ module Public { override string toString() { result = ssa.toString() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - ssa.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = ssa.getLocation() } } private module FunctionNode { @@ -408,11 +391,7 @@ module Public { override string toString() { result = "function " + func.getName() } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - func.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = func.getLocation() } override ResultNode getAResult() { result.getRoot() = this.getFunction().(DeclaredFunction).getFuncDecl() @@ -464,11 +443,7 @@ module Public { override string toString() { result = "[]type{args}" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - call.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = call.getLocation() } } /** @@ -1077,11 +1052,7 @@ module Public { override string toString() { result = "slice element node" } - override predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - si.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + override Location getLocation() { result = si.getLocation() } /** Gets the `SliceNode` which this node relates to. */ SliceNode getSliceNode() { result = DataFlow::instructionNode(si) } diff --git a/go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll b/go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll index f9e569089bef..2d05b211a57e 100644 --- a/go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll +++ b/go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll @@ -301,37 +301,29 @@ class DataFlowCallable extends TDataFlowCallable { result = "Summary: " + this.asSummarizedCallable().toString() } + /** Gets the location of this callable. */ + Location getLocation() { + result = this.asCallable().getLocation() or + result = this.asFileScope().getLocation() or + result = this.asSummarizedCallable().getLocation() + } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this callable is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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.asCallable().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or - this.asFileScope().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or - this.asSummarizedCallable() - .hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } - - /** Gets the location of this callable. */ - Location getLocation() { - result = getCallableLocation(this.asCallable()) or - result = this.asFileScope().getLocation() or - result = getCallableLocation(this.asSummarizedCallable()) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } -private Location getCallableLocation(Callable c) { - exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | - c.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - ) -} - /** A function call relevant for data flow. */ class DataFlowCall extends Expr { DataFlow::CallNode call; diff --git a/go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll b/go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll index dee5d31b78a9..2cd1bbcc7476 100644 --- a/go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll +++ b/go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll @@ -170,17 +170,29 @@ class Content extends TContent { /** Gets a textual representation of this element. */ abstract string toString(); + /** Gets the location of this element. */ + Location getLocation() { none() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0 + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + or + not exists(this.getLocation()) and + filepath = "" and + startline = 0 and + startcolumn = 0 and + endline = 0 and + endcolumn = 0 } /** @@ -202,9 +214,7 @@ class FieldContent extends Content, TFieldContent { override string toString() { result = f.toString() } - override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) { - f.getDeclaration().hasLocationInfo(path, sl, sc, el, ec) - } + override Location getLocation() { result = f.getDeclaration().getLocation() } } /** A reference through the contents of some collection-like container. */ @@ -277,26 +287,31 @@ class ContentSet instanceof TContentSet { /** Gets a textual representation of this content set. */ string toString() { - exists(Content c | this = TOneContent(c) | result = c.toString()) + result = this.asOneContent().toString() or this = TAllContent() and result = "all content" } /** + * Gets the location of this content set, if it contains only one `Content`. + */ + Location getLocation() { result = this.asOneContent().getLocation() } + + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - exists(Content c | this = TOneContent(c) | - c.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - ) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) or - this = TAllContent() and + not exists(this.getLocation()) and filepath = "" and startline = 0 and startcolumn = 0 and diff --git a/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll b/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll index 788b8e3ab662..35887d076c03 100644 --- a/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll +++ b/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll @@ -222,16 +222,17 @@ module SourceSinkInterpretationInput implements /** Gets the location of this element. */ Location getLocation() { - exists(string fp, int sl, int sc, int el, int ec | - this.hasLocationInfo(fp, sl, sc, el, ec) and - result.hasLocationInfo(fp, sl, sc, el, ec) - ) + result = this.asEntity().getLocation() or + result = this.asAstNode().getLocation() } - /** Holds if this element is at the specified location. */ - predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { - this.asEntity().hasLocationInfo(fp, sl, sc, el, ec) or - this.asAstNode().hasLocationInfo(fp, sl, sc, el, ec) + /** + * DEPRECATED: Use `getLocation()` instead. + * + * Holds if this element is at the specified location. + */ + deprecated predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { + this.getLocation().hasLocationInfo(fp, sl, sc, el, ec) } } @@ -280,17 +281,18 @@ module SourceSinkInterpretationInput implements } /** Gets the location of this node. */ - predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { - this.asElement().hasLocationInfo(fp, sl, sc, el, ec) - or - this.asNode().hasLocationInfo(fp, sl, sc, el, ec) + Location getLocation() { + result = this.asElement().getLocation() or + result = this.asNode().getLocation() } - Location getLocation() { - exists(string fp, int sl, int sc, int el, int ec | - this.hasLocationInfo(fp, sl, sc, el, ec) and - result.hasLocationInfo(fp, sl, sc, el, ec) - ) + /** + * DEPRECATED: Use `getLocation()` instead. + * + * Gets the location of this node. + */ + deprecated predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) { + this.getLocation().hasLocationInfo(fp, sl, sc, el, ec) } } diff --git a/go/ql/lib/semmle/go/frameworks/GoMicro.qll b/go/ql/lib/semmle/go/frameworks/GoMicro.qll index b10cca793368..f01dcde9f1ea 100644 --- a/go/ql/lib/semmle/go/frameworks/GoMicro.qll +++ b/go/ql/lib/semmle/go/frameworks/GoMicro.qll @@ -35,7 +35,7 @@ module GoMicro { */ class ProtocMessageType extends Type { ProtocMessageType() { - this.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) and + this.getLocation().getFile() instanceof ProtocGeneratedFile and exists(MethodDecl md | md.getName() = "ProtoMessage" and this = md.getReceiverDecl().getTypeExpr().getAChild().(TypeName).getType() @@ -51,7 +51,7 @@ module GoMicro { ServiceInterfaceType() { this = definedType.getUnderlyingType() and - definedType.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) + definedType.getLocation().getFile() instanceof ProtocGeneratedFile } /** @@ -75,7 +75,7 @@ module GoMicro { ServiceServerType() { this.implements(any(ServiceInterfaceType i)) and this.getName().regexpMatch("(?i).*Handler") and - this.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ProtocGeneratedFile } } @@ -86,7 +86,7 @@ module GoMicro { ClientServiceType() { this.implements(any(ServiceInterfaceType i)) and this.getName().regexpMatch("(?i).*Service") and - this.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ProtocGeneratedFile } } @@ -97,7 +97,7 @@ module GoMicro { ServiceRegisterHandler() { this.getName().regexpMatch("(?i)register" + any(ServiceServerType c).getName()) and this.getParameterType(0) instanceof GoMicroServerType and - this.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ProtocGeneratedFile } } @@ -128,7 +128,7 @@ module GoMicro { this.getName().regexpMatch("(?i)new" + any(ClientServiceType c).getName()) and this.getParameterType(0) instanceof StringType and this.getParameterType(1) instanceof GoMicroClientType and - this.hasLocationInfo(any(ProtocGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ProtocGeneratedFile } } diff --git a/go/ql/lib/semmle/go/frameworks/Twirp.qll b/go/ql/lib/semmle/go/frameworks/Twirp.qll index 10c8106f4017..254949ad7728 100644 --- a/go/ql/lib/semmle/go/frameworks/Twirp.qll +++ b/go/ql/lib/semmle/go/frameworks/Twirp.qll @@ -37,9 +37,7 @@ module Twirp { /** A type representing a protobuf message. */ class ProtobufMessageType extends Type { - ProtobufMessageType() { - this.hasLocationInfo(any(ProtobufGeneratedFile f).getAbsolutePath(), _, _, _, _) - } + ProtobufMessageType() { this.getLocation().getFile() instanceof ProtobufGeneratedFile } } /** An interface type representing a Twirp service. */ @@ -48,7 +46,7 @@ module Twirp { ServiceInterfaceType() { definedType.getUnderlyingType() = this and - definedType.hasLocationInfo(any(ServicesGeneratedFile f).getAbsolutePath(), _, _, _, _) + definedType.getLocation().getFile() instanceof ServicesGeneratedFile } /** Gets the name of the interface. */ @@ -68,7 +66,7 @@ module Twirp { p.implements(i) and this = p.getBaseType() and this.getName().regexpMatch("(?i)" + i.getName() + "(protobuf|json)client") and - this.hasLocationInfo(any(ServicesGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ServicesGeneratedFile ) } } @@ -79,7 +77,7 @@ module Twirp { exists(ServiceInterfaceType i | this.implements(i) and this.getName().regexpMatch("(?i)" + i.getName() + "server") and - this.hasLocationInfo(any(ServicesGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ServicesGeneratedFile ) } } @@ -90,7 +88,7 @@ module Twirp { this.getName().regexpMatch("(?i)new" + any(ServiceClientType c).getName()) and this.getParameterType(0) instanceof StringType and this.getParameterType(1).getName() = "HTTPClient" and - this.hasLocationInfo(any(ServicesGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ServicesGeneratedFile } } @@ -103,7 +101,7 @@ module Twirp { ServerConstructor() { this.getName().regexpMatch("(?i)new" + any(ServiceServerType c).getName()) and this.getParameterType(0) = any(ServiceInterfaceType i).getDefinedType() and - this.hasLocationInfo(any(ServicesGeneratedFile f).getAbsolutePath(), _, _, _, _) + this.getLocation().getFile() instanceof ServicesGeneratedFile } } diff --git a/go/ql/lib/semmle/go/frameworks/stdlib/HtmlTemplate.qll b/go/ql/lib/semmle/go/frameworks/stdlib/HtmlTemplate.qll index 9f44f5742316..f61482c35d72 100644 --- a/go/ql/lib/semmle/go/frameworks/stdlib/HtmlTemplate.qll +++ b/go/ql/lib/semmle/go/frameworks/stdlib/HtmlTemplate.qll @@ -66,7 +66,7 @@ module HtmlTemplate { string getBody() { result = text.regexpCapture("(?s)\\{\\{(.*)\\}\\}", 1) } // matches the inside of the curly bracket delimiters /** Gets the file in which this statement appears. */ - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } + File getFile() { result = this.getLocation().getFile() } /** Gets a textual representation of this statement. */ string toString() { result = "HTML template statement" } @@ -74,17 +74,22 @@ module HtmlTemplate { /** Get the HTML element that contains this template statement. */ HTML::TextNode getEnclosingTextNode() { result = parent } + /** Gets the location of this template statement. */ + Location getLocation() { result = parent.getLocation() } + /** + * DEPRECATED: Use `getLocation()` instead. + * * Holds if this element is at the specified location. * The location spans column `startcolumn` of line `startline` to * column `endcolumn` of line `endline` in file `filepath`. * 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 ) { - parent.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) } } @@ -114,7 +119,7 @@ module HtmlTemplate { } /** Gets the file in which this read appears. */ - File getFile() { this.hasLocationInfo(result.getAbsolutePath(), _, _, _, _) } + File getFile() { result = this.getLocation().getFile() } /** Gets a textual representation of this statement. */ string toString() { result = "HTML template read of " + text } @@ -122,17 +127,21 @@ module HtmlTemplate { /** Get the HTML element that contains this template read. */ HTML::TextNode getEnclosingTextNode() { result = parent.getEnclosingTextNode() } - /** - * Holds if this element is at the specified location. - * The location spans column `startcolumn` of line `startline` to - * column `endcolumn` of line `endline` in file `filepath`. - * For more information, see - * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). - */ - predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - parent.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + /** Gets the location of this template statement. */ + Location getLocation() { result = parent.getLocation() } + // /** + // * DEPRECATED: Use `getLocation()` instead. + // * + // * Holds if this element is at the specified location. + // * The location spans column `startcolumn` of line `startline` to + // * column `endcolumn` of line `endline` in file `filepath`. + // * For more information, see + // * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). + // */ + // predicate hasLocationInfo( + // string filepath, int startline, int startcolumn, int endline, int endcolumn + // ) { + // this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + // } } } diff --git a/go/ql/src/InconsistentCode/WhitespaceContradictsPrecedence.ql b/go/ql/src/InconsistentCode/WhitespaceContradictsPrecedence.ql index 7dde89c445f1..f2303cf08a61 100644 --- a/go/ql/src/InconsistentCode/WhitespaceContradictsPrecedence.ql +++ b/go/ql/src/InconsistentCode/WhitespaceContradictsPrecedence.ql @@ -72,11 +72,14 @@ predicate interestingNesting(BinaryExpr inner, BinaryExpr outer) { /** Gets the number of whitespace characters around the operator `op` of `be`. */ int getWhitespaceAroundOperator(BinaryExpr be, string op) { - exists(string file, int line, int left, int right | - be.getLeftOperand().hasLocationInfo(file, _, _, line, left) and - be.getRightOperand().hasLocationInfo(file, line, right, _, _) and + exists(Location left, Location right | + be.getLeftOperand().getLocation() = left and + be.getRightOperand().getLocation() = right and + left.getFile() = right.getFile() and + left.getStartLine() = right.getStartLine() + | op = be.getOperator() and - result = (right - left - op.length() - 1) / 2 + result = (right.getStartColumn() - left.getEndColumn() - op.length() - 1) / 2 ) } diff --git a/go/ql/test/experimental/CWE-522-DecompressionBombs/DecompressionBombTest.ql b/go/ql/test/experimental/CWE-522-DecompressionBombs/DecompressionBombTest.ql index ec22f6579513..d33309129814 100644 --- a/go/ql/test/experimental/CWE-522-DecompressionBombs/DecompressionBombTest.ql +++ b/go/ql/test/experimental/CWE-522-DecompressionBombs/DecompressionBombTest.ql @@ -10,8 +10,7 @@ module TestDecompressionBombs implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "hasValueFlow" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "\"" + sink.toString() + "\"" ) diff --git a/go/ql/test/experimental/frameworks/CleverGo/HeaderWrite.ql b/go/ql/test/experimental/frameworks/CleverGo/HeaderWrite.ql index b34343008b50..1406b4a0e2fb 100644 --- a/go/ql/test/experimental/frameworks/CleverGo/HeaderWrite.ql +++ b/go/ql/test/experimental/frameworks/CleverGo/HeaderWrite.ql @@ -8,8 +8,7 @@ module HttpHeaderWriteTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { // Dynamic key-value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getName().toString() and value = hw.getName().toString() and @@ -23,8 +22,7 @@ module HttpHeaderWriteTest implements TestSig { or // Static key, dynamic value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getHeaderName().toString() and value = hw.getHeaderName() and @@ -38,8 +36,7 @@ module HttpHeaderWriteTest implements TestSig { or // Static key, static value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getHeaderName().toString() and value = hw.getHeaderName() and diff --git a/go/ql/test/experimental/frameworks/CleverGo/HttpRedirect.ql b/go/ql/test/experimental/frameworks/CleverGo/HttpRedirect.ql index 20062ad73586..d29a51f4c881 100644 --- a/go/ql/test/experimental/frameworks/CleverGo/HttpRedirect.ql +++ b/go/ql/test/experimental/frameworks/CleverGo/HttpRedirect.ql @@ -8,8 +8,7 @@ module HttpRedirectTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "redirectUrl" and exists(Http::Redirect rd | - rd.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + rd.getLocation() = location and element = rd.getUrl().toString() and value = rd.getUrl().toString() ) diff --git a/go/ql/test/experimental/frameworks/CleverGo/HttpResponseBody.ql b/go/ql/test/experimental/frameworks/CleverGo/HttpResponseBody.ql index 8842edcada11..1b95ba9b331a 100644 --- a/go/ql/test/experimental/frameworks/CleverGo/HttpResponseBody.ql +++ b/go/ql/test/experimental/frameworks/CleverGo/HttpResponseBody.ql @@ -7,8 +7,7 @@ module HttpResponseBodyTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(Http::ResponseBody rd | - rd.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + rd.getLocation() = location and ( element = rd.getAContentType().toString() and value = rd.getAContentType().toString() and diff --git a/go/ql/test/experimental/frameworks/CleverGo/RemoteSources.ql b/go/ql/test/experimental/frameworks/CleverGo/RemoteSources.ql index 3c7cb4f7f106..6cc15f553134 100644 --- a/go/ql/test/experimental/frameworks/CleverGo/RemoteSources.ql +++ b/go/ql/test/experimental/frameworks/CleverGo/RemoteSources.ql @@ -14,8 +14,7 @@ module RemoteFlowSourceTest implements TestSig { | element = arg.toString() and value = "" and - arg.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + arg.getLocation() = location ) } } diff --git a/go/ql/test/experimental/frameworks/Fiber/HeaderWrite.ql b/go/ql/test/experimental/frameworks/Fiber/HeaderWrite.ql index 8ea18121f0ae..76963c4a742d 100644 --- a/go/ql/test/experimental/frameworks/Fiber/HeaderWrite.ql +++ b/go/ql/test/experimental/frameworks/Fiber/HeaderWrite.ql @@ -8,8 +8,7 @@ module HttpHeaderWriteTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { // Dynamic key-value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getName().toString() and value = hw.getName().toString() and @@ -23,8 +22,7 @@ module HttpHeaderWriteTest implements TestSig { or // Static key, dynamic value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getHeaderName().toString() and value = hw.getHeaderName() and @@ -38,8 +36,7 @@ module HttpHeaderWriteTest implements TestSig { or // Static key, static value header: exists(Http::HeaderWrite hw | - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + hw.getLocation() = location and ( element = hw.getHeaderName().toString() and value = hw.getHeaderName() and diff --git a/go/ql/test/experimental/frameworks/Fiber/Redirect.ql b/go/ql/test/experimental/frameworks/Fiber/Redirect.ql index ace56e3e0c8e..9fea71d021e1 100644 --- a/go/ql/test/experimental/frameworks/Fiber/Redirect.ql +++ b/go/ql/test/experimental/frameworks/Fiber/Redirect.ql @@ -8,8 +8,7 @@ module HttpRedirectTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "redirectUrl" and exists(Http::Redirect rd | - rd.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + rd.getLocation() = location and element = rd.getUrl().toString() and value = rd.getUrl().toString() ) diff --git a/go/ql/test/experimental/frameworks/Fiber/RemoteFlowSources.ql b/go/ql/test/experimental/frameworks/Fiber/RemoteFlowSources.ql index e6d40fdd2cfe..68c43d4af339 100644 --- a/go/ql/test/experimental/frameworks/Fiber/RemoteFlowSources.ql +++ b/go/ql/test/experimental/frameworks/Fiber/RemoteFlowSources.ql @@ -14,8 +14,7 @@ module RemoteFlowSourceTest implements TestSig { | element = arg.toString() and value = "" and - arg.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + arg.getLocation() = location ) } } diff --git a/go/ql/test/experimental/frameworks/Fiber/ResponseBody.ql b/go/ql/test/experimental/frameworks/Fiber/ResponseBody.ql index 8ef63f48f64b..bd6b92b6f49e 100644 --- a/go/ql/test/experimental/frameworks/Fiber/ResponseBody.ql +++ b/go/ql/test/experimental/frameworks/Fiber/ResponseBody.ql @@ -7,8 +7,7 @@ module HttpResponseBodyTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(Http::ResponseBody rd | - rd.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + rd.getLocation() = location and ( element = rd.getAContentType().toString() and value = rd.getAContentType().toString() and diff --git a/go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql b/go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql index 797405e7c89b..202a437d6a0b 100644 --- a/go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql +++ b/go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql @@ -1,7 +1,7 @@ import go query predicate numberOfTypeParameters(TypeParamParentEntity parent, int n) { - exists(string file | file != "" | parent.hasLocationInfo(file, _, _, _, _)) and + exists(parent.getLocation().getFile()) and n = strictcount(TypeParamType tpt | tpt.getParent() = parent) } diff --git a/go/ql/test/library-tests/semmle/go/Function/isVariadic.ql b/go/ql/test/library-tests/semmle/go/Function/isVariadic.ql index 711f535c7931..f27a971c0137 100644 --- a/go/ql/test/library-tests/semmle/go/Function/isVariadic.ql +++ b/go/ql/test/library-tests/semmle/go/Function/isVariadic.ql @@ -7,8 +7,7 @@ module FunctionIsVariadicTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(CallExpr ce | ce.getTarget().isVariadic() and - ce.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + ce.getLocation() = location and element = ce.toString() and value = "" and tag = "isVariadic" diff --git a/go/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql b/go/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql index eb6e96cdcd86..6e67cbb592c7 100644 --- a/go/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql +++ b/go/ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql @@ -5,9 +5,9 @@ import go * that contains the substring "`kind`,`dep`,`ver`". */ predicate metadata(Locatable l, string kind, string mod, string dep, string ver) { - exists(string f, int line, Comment c, string text | - l.hasLocationInfo(f, line, _, _, _) and - c.hasLocationInfo(f, line, _, _, _) + exists(Comment c, string text | + l.getFile() = c.getFile() and + l.getLocation().getStartLine() = c.getLocation().getStartLine() | text = c.getText().regexpFind("\\b([^,\\s]+,[^,]+,[^,]+,[^,\\s]+)", _, _) and kind = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 1) and @@ -19,27 +19,27 @@ predicate metadata(Locatable l, string kind, string mod, string dep, string ver) query predicate missingRequire(string mod, string dep, string ver, int line) { exists(Locatable l | metadata(l, "RequireLine", mod, dep, ver) | - l.hasLocationInfo(_, line, _, _, _) + line = l.getLocation().getStartLine() ) and not exists(GoModRequireLine req | req.getModulePath() = mod and req.getPath() = dep and req.getVersion() = ver and metadata(req, "RequireLine", mod, dep, ver) and - req.hasLocationInfo(_, line, _, _, _) + line = req.getLocation().getStartLine() ) } query predicate missingExclude(string mod, string dep, string ver, int line) { exists(Locatable l | metadata(l, "ExcludeLine", mod, dep, ver) | - l.hasLocationInfo(_, line, _, _, _) + line = l.getLocation().getStartLine() ) and not exists(GoModExcludeLine exc | exc.getModulePath() = mod and exc.getPath() = dep and exc.getVersion() = ver and metadata(exc, "ExcludeLine", mod, dep, ver) and - exc.hasLocationInfo(_, line, _, _, _) + line = exc.getLocation().getStartLine() ) } @@ -48,9 +48,9 @@ query predicate missingExclude(string mod, string dep, string ver, int line) { * that contains the substring "ReplaceLine,`mod`,`dep`,`dver`,`rep`,`rver`". */ predicate repmetadata(Locatable l, string mod, string dep, string dver, string rep, string rver) { - exists(string f, int line, Comment c, string text | - l.hasLocationInfo(f, line, _, _, _) and - c.hasLocationInfo(f, line, _, _, _) + exists(Comment c, string text | + l.getFile() = c.getFile() and + l.getLocation().getStartLine() = c.getLocation().getStartLine() | text = c.getText().regexpFind("\\b(ReplaceLine,[^,]*,[^,]*,[^,]*,[^,]*,[^,\\s]*)", _, _) and mod = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 1) and @@ -65,7 +65,7 @@ query predicate missingReplace( string mod, string dep, string dver, string rep, string rver, int line ) { exists(Locatable l | repmetadata(l, mod, dep, dver, rep, rver) | - l.hasLocationInfo(_, line, _, _, _) + line = l.getLocation().getStartLine() ) and not exists(GoModReplaceLine repl | ( @@ -85,6 +85,6 @@ query predicate missingReplace( repl.getOriginalPath() = dep and repl.getReplacementPath() = rep and repmetadata(repl, mod, dep, dver, rep, rver) and - repl.hasLocationInfo(_, line, _, _, _) + line = repl.getLocation().getStartLine() ) } diff --git a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql index d4c15358f06c..dd50a89ed6dc 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Aliases.ql +++ b/go/ql/test/library-tests/semmle/go/Types/Aliases.ql @@ -12,10 +12,9 @@ query predicate entities(string fp, Entity e, int c, Type ty) { ) } -from string fp, FuncDecl decl, SignatureType sig +from FuncDecl decl, SignatureType sig where - decl.hasLocationInfo(fp, _, _, _, _) and + decl.getFile().getAbsolutePath().matches("%aliases.go%") and decl.getName() = ["F", "G", "H"] and - sig = decl.getType() and - fp.matches("%aliases.go%") + sig = decl.getType() select decl.getName(), sig.pp() diff --git a/go/ql/test/library-tests/semmle/go/Types/ImplementsComparable.ql b/go/ql/test/library-tests/semmle/go/Types/ImplementsComparable.ql index 9afa5505801e..f78ad065c828 100644 --- a/go/ql/test/library-tests/semmle/go/Types/ImplementsComparable.ql +++ b/go/ql/test/library-tests/semmle/go/Types/ImplementsComparable.ql @@ -11,8 +11,7 @@ module ImplementsComparableTest implements TestSig { ts.getName().matches("testComparable%") and ts.getATypeParameterDecl().getTypeConstraint().implementsComparable() | - ts.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + ts.getLocation() = location and element = ts.getName() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/Types/SignatureType_isVariadic.ql b/go/ql/test/library-tests/semmle/go/Types/SignatureType_isVariadic.ql index 6a4b42700232..96569918de1f 100644 --- a/go/ql/test/library-tests/semmle/go/Types/SignatureType_isVariadic.ql +++ b/go/ql/test/library-tests/semmle/go/Types/SignatureType_isVariadic.ql @@ -7,8 +7,7 @@ module SignatureTypeIsVariadicTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(FuncDef fd | fd.isVariadic() and - fd.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + fd.getLocation() = location and element = fd.toString() and value = "" and tag = "isVariadic" diff --git a/go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.ql b/go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.ql index cb3fa3137544..8bed0251cba9 100644 --- a/go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.ql +++ b/go/ql/test/library-tests/semmle/go/aliases/MethodDefs/test.ql @@ -11,11 +11,7 @@ class EntityWithDeclInfo extends TEntityWithDeclInfo { string toString() { result = e.toString() + " (" + nDecls + " declaration sites)" } - predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + Location getLocation() { result = e.getLocation() } } query predicate distinctDefinedFs(int ct) { ct = count(DeclaredFunction e | e.toString() = "F") } diff --git a/go/ql/test/library-tests/semmle/go/aliases/defsuses/test.ql b/go/ql/test/library-tests/semmle/go/aliases/defsuses/test.ql index 923550d547eb..2d0fe6e888d4 100644 --- a/go/ql/test/library-tests/semmle/go/aliases/defsuses/test.ql +++ b/go/ql/test/library-tests/semmle/go/aliases/defsuses/test.ql @@ -11,11 +11,7 @@ class EntityWithDeclInfo extends TEntityWithDeclInfo { result = e.toString() + " (" + count(e.getDeclaration()) + " declaration sites)" } - predicate hasLocationInfo( - string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } + Location getLocation() { result = e.getLocation() } } query predicate lowLevelDefs(Ident i, EntityWithDeclInfo ewrapped) { diff --git a/go/ql/test/library-tests/semmle/go/concepts/HTTP/Handler.ql b/go/ql/test/library-tests/semmle/go/concepts/HTTP/Handler.ql index 6695162b954a..0071d0f2d756 100644 --- a/go/ql/test/library-tests/semmle/go/concepts/HTTP/Handler.ql +++ b/go/ql/test/library-tests/semmle/go/concepts/HTTP/Handler.ql @@ -9,8 +9,7 @@ module HttpHandler implements TestSig { exists(Http::RequestHandler h, DataFlow::Node check | element = h.toString() and value = check.toString() | - h.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + h.getLocation() = location and h.guardedBy(check) ) } diff --git a/go/ql/test/library-tests/semmle/go/concepts/LoggerCall/LoggerCall.ql b/go/ql/test/library-tests/semmle/go/concepts/LoggerCall/LoggerCall.ql index b15d129039eb..7eef263ec830 100644 --- a/go/ql/test/library-tests/semmle/go/concepts/LoggerCall/LoggerCall.ql +++ b/go/ql/test/library-tests/semmle/go/concepts/LoggerCall/LoggerCall.ql @@ -8,8 +8,7 @@ module LoggerTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(LoggerCall log | - log.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + log.getLocation() = location and element = log.toString() and value = log.getAMessageComponent().toString() and tag = "logger" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.ql b/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.ql index 99e85587d55d..063fabad9cb3 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.ql @@ -5,9 +5,9 @@ import go * that contains the substring `key: val`. */ string metadata(Locatable l, string key) { - exists(string f, int line, Comment c, string kv | - l.hasLocationInfo(f, line, _, _, _) and - c.hasLocationInfo(f, line, _, _, _) and + exists(Comment c, string kv | + l.getFile() = c.getFile() and + l.getLocation().getStartLine() = c.getLocation().getStartLine() and kv = c.getText().regexpFind("\\b(\\w+: \\S+)", _, _) and key = kv.regexpCapture("(\\w+): (\\S+)", 1) and result = kv.regexpCapture("(\\w+): (\\S+)", 2) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.ql b/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.ql index 5c157e7fffa1..33865e18be12 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.ql @@ -6,9 +6,9 @@ import semmle.go.dataflow.internal.DataFlowDispatch * that contains the substring `key: val`. */ string metadata(Locatable l, string key) { - exists(string f, int line, Comment c, string kv | - l.hasLocationInfo(f, line, _, _, _) and - c.hasLocationInfo(f, line, _, _, _) and + exists(Comment c, string kv | + l.getFile() = c.getFile() and + l.getLocation().getStartLine() = c.getLocation().getStartLine() and kv = c.getText().regexpFind("\\b(\\w+: \\S+)", _, _) and key = kv.regexpCapture("(\\w+): (\\S+)", 1) and result = kv.regexpCapture("(\\w+): (\\S+)", 2) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_false.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_false.ql index 24ad16a00675..c69cedce6e17 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_false.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_false.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "I1[f]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_true.ql index 20702a237ceb..0e57da78df1f 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "I1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_false.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_false.ql index 90a277cb944d..254c75804934 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_false.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_false.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "I2[f]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_true.ql index f9e5566438f7..078bf80b0178 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_I2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "I2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI1_subtypes_true.ql index c98607c88f51..16669ec1aa5b 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "IEmbedI1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI2_subtypes_true.ql index 0fa7372c504c..603a154a63f3 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_IEmbedI2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "IEmbedI2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI1_subtypes_true.ql index 4b34a2e99ab2..f01190de4add 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "PImplEmbedI1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI2_subtypes_true.ql index 2eb869023409..88cef7e2c759 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_PImplEmbedI2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "PImplEmbedI2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_false.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_false.ql index a154ca95a3db..62320657df27 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_false.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_false.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "S1[f]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_true.ql index 45740e13afe2..c3812d66b2a1 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_S1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "S1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI1_subtypes_true.ql index 3536fed2a259..62d14a0d04a5 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedI1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI2_subtypes_true.ql index 6daadc65db48..4758cc409466 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedI2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedI2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP1_subtypes_true.ql index b9d4b72c7268..407f1eda0c42 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedP1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP2_subtypes_true.ql index dfbe91185342..218b65468c77 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedP2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedP2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP1_subtypes_true.ql index edc94546a06a..930819571af0 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedPtrP1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP2_subtypes_true.ql index 7370b73839ea..5881f7903105 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrP2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedPtrP2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS1_subtypes_true.ql index 39a5759f248b..a178e0947644 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedPtrS1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS2_subtypes_true.ql index d40fe60ff112..23ce8b52285d 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedPtrS2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedPtrS2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS1_subtypes_true.ql index e103f7f631a7..f8a66769dac0 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedS1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS2_subtypes_true.ql index a461b2da08dd..05bd2296a7bd 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SEmbedS2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SEmbedS2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI1_subtypes_true.ql index aac7a180ae87..3f9e6d9cca50 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SImplEmbedI1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI2_subtypes_true.ql index 25c3b7959dcd..21c431860fe7 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedI2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SImplEmbedI2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS1_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS1_subtypes_true.ql index 429d3a527d59..813ea620a0c6 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS1_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS1_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SImplEmbedS1[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS2_subtypes_true.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS2_subtypes_true.ql index e55fdf59a222..7a3105aaf71a 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS2_subtypes_true.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/mad_SImplEmbedS2_subtypes_true.ql @@ -17,8 +17,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "SImplEmbedS2[t]" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_I1.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_I1.ql index e5d80402faa1..181c55b29df9 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_I1.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_I1.ql @@ -27,8 +27,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "ql_I1" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_P1.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_P1.ql index cdabb83a7362..e82a6cb4da10 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_P1.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_P1.ql @@ -37,8 +37,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "ql_P1" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_S1.ql b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_S1.ql index a159d1ae5ed1..c4124dcd10e5 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_S1.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/ExternalFlowInheritance/ql_S1.ql @@ -37,8 +37,7 @@ module FlowTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "ql_S1" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "" ) diff --git a/go/ql/test/library-tests/semmle/go/dataflow/PromotedMethods/DataFlowConfig.ql b/go/ql/test/library-tests/semmle/go/dataflow/PromotedMethods/DataFlowConfig.ql index fa8367236db3..e3a3a4d77d92 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/PromotedMethods/DataFlowConfig.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/PromotedMethods/DataFlowConfig.ql @@ -11,8 +11,7 @@ module PromotedMethodsTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(DataFlow::Node source, DataFlow::Node sink | ValueFlow::flow(source, sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = source.getEnclosingCallable().getName() and tag = "promotedmethods" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql index 924c655bf655..721fc7aa53cb 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql @@ -7,8 +7,7 @@ module SourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(ActiveThreatModelSource s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = "" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/source.ql b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/source.ql index 924c655bf655..721fc7aa53cb 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/source.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/source.ql @@ -7,8 +7,7 @@ module SourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(ActiveThreatModelSource s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = "" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/environment/test.ql b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/environment/test.ql index 924c655bf655..721fc7aa53cb 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/environment/test.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/environment/test.ql @@ -7,8 +7,7 @@ module SourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(ActiveThreatModelSource s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = "" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file/test.ql b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file/test.ql index 924c655bf655..721fc7aa53cb 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file/test.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file/test.ql @@ -7,8 +7,7 @@ module SourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(ActiveThreatModelSource s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = "" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/stdin/source.ql b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/stdin/source.ql index 924c655bf655..721fc7aa53cb 100644 --- a/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/stdin/source.ql +++ b/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/stdin/source.ql @@ -7,8 +7,7 @@ module SourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(ActiveThreatModelSource s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = "" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Afero/Query.ql b/go/ql/test/library-tests/semmle/go/frameworks/Afero/Query.ql index 87ac0330e994..b9ba68d2acb4 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Afero/Query.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Afero/Query.ql @@ -8,8 +8,7 @@ module FileSystemAccessTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(FileSystemAccess fsa | - fsa.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + fsa.getLocation() = location and element = fsa.getAPathArgument().toString() and value = fsa.getAPathArgument().toString() and tag = "FileSystemAccess" @@ -18,14 +17,12 @@ module FileSystemAccessTest implements TestSig { exists(DataFlow::Node succ, DataFlow::Node pred | any(Afero::AdditionalTaintStep adts).step(pred, succ) | - succ.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + succ.getLocation() = location and element = succ.toString() and value = succ.asExpr().(StructLit).getType().getName() and tag = "succ" or - pred.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + pred.getLocation() = location and element = pred.toString() and value = pred.toString() and tag = "pred" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/BeegoOrm/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/BeegoOrm/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/BeegoOrm/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/BeegoOrm/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/CouchbaseV1/test.ql b/go/ql/test/library-tests/semmle/go/frameworks/CouchbaseV1/test.ql index da91c22b2dd4..7bd24283a902 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/CouchbaseV1/test.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/CouchbaseV1/test.ql @@ -12,8 +12,7 @@ module SqlInjectionTest implements TestSig { exists(DataFlow::Node sink | SqlInjection::Flow::flowTo(sink) | element = sink.toString() and value = sink.toString() and - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + sink.getLocation() = location ) } } diff --git a/go/ql/test/library-tests/semmle/go/frameworks/ElazarlGoproxy/test.ql b/go/ql/test/library-tests/semmle/go/frameworks/ElazarlGoproxy/test.ql index a2713304a5d1..f1f443aee169 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/ElazarlGoproxy/test.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/ElazarlGoproxy/test.ql @@ -10,8 +10,7 @@ module RemoteFlowSourceTest implements TestSig { tag = "remoteflowsource" and value = element and exists(RemoteFlowSource src | value = "\"" + src.toString() + "\"" | - src.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + src.getLocation() = location ) } } @@ -24,8 +23,7 @@ module HeaderWriteTest implements TestSig { exists(Http::HeaderWrite hw, string name, string val | element = hw.toString() | hw.definesHeader(name, val) and value = name + ":" + val and - hw.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + hw.getLocation() = location ) } } @@ -35,8 +33,7 @@ module LoggerTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(LoggerCall log | - log.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + log.getLocation() = location and element = log.toString() and value = log.getAMessageComponent().toString() and tag = "logger" @@ -64,9 +61,7 @@ module TaintFlow implements TestSig { value = "" and element = "" and exists(DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flowTo(toNode) ) } diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/EscapeFunction.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/EscapeFunction.ql index 5c623417dd44..b34c35cab4fc 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/EscapeFunction.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/EscapeFunction.ql @@ -6,8 +6,7 @@ module FasthttpTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(EscapeFunction ef, DataFlow::CallNode cn | cn = ef.getACall() | - cn.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + cn.getLocation() = location and element = cn.getArgument(1).toString() and value = cn.getArgument(1).toString() and tag = "Sanitizer" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/FileSystemAccess.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/FileSystemAccess.ql index bce6d70999f0..3e6ebd5ae7aa 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/FileSystemAccess.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/FileSystemAccess.ql @@ -8,9 +8,7 @@ module FasthttpFileSystemAccessTest implements TestSig { exists(FileSystemAccess fileSystemAccess, DataFlow::Node aPathArgument | aPathArgument = fileSystemAccess.getAPathArgument() | - aPathArgument - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + aPathArgument.getLocation() = location and element = aPathArgument.toString() and value = aPathArgument.toString() and tag = "FileSystemAccess" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/OpenRedirect.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/OpenRedirect.ql index 397ceb5c9f85..243c84e44d00 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/OpenRedirect.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/OpenRedirect.ql @@ -7,8 +7,7 @@ module FasthttpTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(OpenUrlRedirect::Sink s | - s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + s.getLocation() = location and element = s.toString() and value = s.toString() and tag = "OpenRedirect" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/RemoteFlowSources.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/RemoteFlowSources.ql index 1adbb0d2f64c..9a97c6886687 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/RemoteFlowSources.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/RemoteFlowSources.ql @@ -6,9 +6,7 @@ module FasthttpTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(RemoteFlowSource source | - source - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + source.getLocation() = location and element = source.toString() and value = "\"" + source.toString() + "\"" and tag = "RemoteFlowSource" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/SSRF.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/SSRF.ql index 2b43216d6dd0..b19c5b3839cb 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/SSRF.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/SSRF.ql @@ -7,9 +7,7 @@ module FasthttpTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(RequestForgery::Sink ssrfSink | - ssrfSink - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + ssrfSink.getLocation() = location and element = ssrfSink.toString() and value = ssrfSink.toString() and tag = "SsrfSink" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/Xss.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/Xss.ql index b7ea0ebd8f72..99771d205b84 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/Xss.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/Xss.ql @@ -6,9 +6,7 @@ module FasthttpTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(SharedXss::Sink xssSink | - xssSink - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + xssSink.getLocation() = location and element = xssSink.toString() and value = xssSink.toString() and tag = "XssSink" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Fiber/Query.ql b/go/ql/test/library-tests/semmle/go/frameworks/Fiber/Query.ql index bd11df4db16f..d95d3b7591ca 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Fiber/Query.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Fiber/Query.ql @@ -8,8 +8,7 @@ module FileSystemAccessTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(FileSystemAccess fsa | - fsa.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + fsa.getLocation() = location and element = fsa.getAPathArgument().toString() and value = fsa.getAPathArgument().toString() and tag = "FileSystemAccess" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/GoKit/RemoteFlowSources.ql b/go/ql/test/library-tests/semmle/go/frameworks/GoKit/RemoteFlowSources.ql index cc77baf9be3a..e9e84b926c38 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/GoKit/RemoteFlowSources.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/GoKit/RemoteFlowSources.ql @@ -8,9 +8,7 @@ module RemoteFlowSourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(RemoteFlowSource source | - source - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + source.getLocation() = location and element = source.toString() and value = "\"" + source.toString() + "\"" and tag = "source" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/GoMicro/gomicro.ql b/go/ql/test/library-tests/semmle/go/frameworks/GoMicro/gomicro.ql index 954aff43ad34..9b5bf02a1744 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/GoMicro/gomicro.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/GoMicro/gomicro.ql @@ -8,8 +8,7 @@ module GoMicroTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(DataFlow::Node node | - node.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + node.getLocation() = location and ( node instanceof GoMicro::Request and element = node.toString() and diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Iris/Query.ql b/go/ql/test/library-tests/semmle/go/frameworks/Iris/Query.ql index bd11df4db16f..d95d3b7591ca 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Iris/Query.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Iris/Query.ql @@ -8,8 +8,7 @@ module FileSystemAccessTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(FileSystemAccess fsa | - fsa.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + fsa.getLocation() = location and element = fsa.getAPathArgument().toString() and value = fsa.getAPathArgument().toString() and tag = "FileSystemAccess" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/K8sIoClientGo/SecretInterfaceSource.ql b/go/ql/test/library-tests/semmle/go/frameworks/K8sIoClientGo/SecretInterfaceSource.ql index 786b01d6a462..bb674d88ed07 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/K8sIoClientGo/SecretInterfaceSource.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/K8sIoClientGo/SecretInterfaceSource.ql @@ -8,9 +8,7 @@ module K8sIoApimachineryPkgRuntimeTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(K8sIoClientGo::SecretInterfaceSource source | - source - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + source.getLocation() = location and element = source.toString() and value = "" and tag = "KsIoClientGo" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Macaron/Sources.ql b/go/ql/test/library-tests/semmle/go/frameworks/Macaron/Sources.ql index cde8cc6ea2d6..dfe7b59a7934 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Macaron/Sources.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Macaron/Sources.ql @@ -8,8 +8,7 @@ module RemoteFlowSourceTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(RemoteFlowSource src | - src.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + src.getLocation() = location and element = src.toString() and value = "" and tag = "RemoteFlowSource" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/NoSQL/Query.ql b/go/ql/test/library-tests/semmle/go/frameworks/NoSQL/Query.ql index db8f145d70c4..64612aa010cb 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/NoSQL/Query.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/NoSQL/Query.ql @@ -8,8 +8,7 @@ module NoSqlQueryTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(NoSql::Query q | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = q.toString() and tag = "nosqlquery" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Revel/test.ql b/go/ql/test/library-tests/semmle/go/frameworks/Revel/test.ql index 2ac3c51c93d1..9e560c44cedb 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Revel/test.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Revel/test.ql @@ -23,8 +23,7 @@ module MissingDataFlowTest implements TestSig { value = "" and exists(Sink sink | not TestFlow::flowTo(sink) and - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() ) } @@ -36,8 +35,7 @@ module HttpResponseBodyTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "responsebody" and exists(Http::ResponseBody rb | - rb.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + rb.getLocation() = location and element = rb.toString() and value = "'" + rb.toString() + "'" ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/Gorm/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/Gorm/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/Gorm/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/Gorm/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/Sqlx/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/Sqlx/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/Sqlx/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/Sqlx/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/gogf/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/gogf/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/gogf/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/gogf/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/SQL/gorqlite/QueryString.ql b/go/ql/test/library-tests/semmle/go/frameworks/SQL/gorqlite/QueryString.ql index 0d56af8659c4..fa869181ed94 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/SQL/gorqlite/QueryString.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/SQL/gorqlite/QueryString.ql @@ -9,8 +9,7 @@ module SqlTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "query" and exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | - q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + q.getLocation() = location and element = q.toString() and value = qs.toString() ) @@ -24,8 +23,7 @@ module QueryString implements TestSig { tag = "querystring" and element = "" and exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | - qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + qs.getLocation() = location and value = qs.toString() ) } @@ -48,9 +46,7 @@ module TaintFlow implements TestSig { tag = "flowfrom" and element = "" and exists(DataFlow::Node fromNode, DataFlow::Node toNode | - toNode - .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + toNode.getLocation() = location and Flow::flow(fromNode, toNode) and value = fromNode.asExpr().(StringLit).getValue() ) diff --git a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/test.ql b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/test.ql index 3c939a9ccefd..9e1d8021fe4b 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/test.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/test.ql @@ -8,8 +8,7 @@ module FileSystemAccessTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { exists(FileSystemAccess f | - f.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + f.getLocation() = location and element = f.toString() and value = f.getAPathArgument().toString() and tag = "fsaccess" diff --git a/go/ql/test/library-tests/semmle/go/frameworks/Yaml/tests.ql b/go/ql/test/library-tests/semmle/go/frameworks/Yaml/tests.ql index c47d1fee2fa8..96d1d420fc1a 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/Yaml/tests.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/Yaml/tests.ql @@ -39,8 +39,7 @@ module TaintFunctionModelTest implements TestSig { tag = "ttfnmodelstep" and ( exists(TaintTracking::FunctionModel model, DataFlow::CallNode call | call = model.getACall() | - call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + call.getLocation() = location and element = call.toString() and value = "\"" + model.getAnInputNode(call) + " -> " + model.getAnOutputNode(call) + "\"" ) @@ -48,8 +47,7 @@ module TaintFunctionModelTest implements TestSig { exists(DataFlow::Node arg, DataFlow::Node output | TaintTransitsFunctionFlow::flow(arg, output) and isSourceSinkPair(arg, output) and - arg.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + arg.getLocation() = location and element = arg.toString() and value = "\"" + arg + " -> " + output + "\"" ) @@ -63,8 +61,7 @@ module MarshalerTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "marshaler" and exists(MarshalingFunction m, DataFlow::CallNode call | call = m.getACall() | - call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + call.getLocation() = location and element = call.toString() and value = "\"" + m.getFormat() + ": " + m.getAnInput().getNode(call) + " -> " + @@ -79,8 +76,7 @@ module UnmarshalerTest implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "unmarshaler" and exists(UnmarshalingFunction m, DataFlow::CallNode call | call = m.getACall() | - call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + call.getLocation() = location and element = call.toString() and value = "\"" + m.getFormat() + ": " + m.getAnInput().getNode(call) + " -> " + diff --git a/go/ql/test/library-tests/semmle/go/frameworks/gqlgen/gqlgen.ql b/go/ql/test/library-tests/semmle/go/frameworks/gqlgen/gqlgen.ql index c18b117edc4d..8f99a78ab100 100644 --- a/go/ql/test/library-tests/semmle/go/frameworks/gqlgen/gqlgen.ql +++ b/go/ql/test/library-tests/semmle/go/frameworks/gqlgen/gqlgen.ql @@ -11,8 +11,7 @@ module ResolveParameterTest implements TestSig { exists(Gqlgen::ResolverParameter p | element = p.toString() and value = "\"" + p.toString() + "\"" and - p.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) + p.getLocation() = location ) } } diff --git a/go/ql/test/query-tests/Security/CWE-681/IncorrectIntegerConversion.ql b/go/ql/test/query-tests/Security/CWE-681/IncorrectIntegerConversion.ql index 9c9a00e825a6..e5d1b2aebabe 100644 --- a/go/ql/test/query-tests/Security/CWE-681/IncorrectIntegerConversion.ql +++ b/go/ql/test/query-tests/Security/CWE-681/IncorrectIntegerConversion.ql @@ -10,8 +10,7 @@ module TestIncorrectIntegerConversion implements TestSig { predicate hasActualResult(Location location, string element, string tag, string value) { tag = "hasValueFlow" and exists(DataFlow::Node sink | Flow::flowTo(sink) | - sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and + sink.getLocation() = location and element = sink.toString() and value = "\"" + sink.toString() + "\"" ) From a94854bd722725e680ae2ce271694651b106207f Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 27 Feb 2025 12:35:57 +0000 Subject: [PATCH 3/3] Add change note --- .../lib/change-notes/2025-02-27-haslocationinfo-deprecated.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 go/ql/lib/change-notes/2025-02-27-haslocationinfo-deprecated.md diff --git a/go/ql/lib/change-notes/2025-02-27-haslocationinfo-deprecated.md b/go/ql/lib/change-notes/2025-02-27-haslocationinfo-deprecated.md new file mode 100644 index 000000000000..b51793a215df --- /dev/null +++ b/go/ql/lib/change-notes/2025-02-27-haslocationinfo-deprecated.md @@ -0,0 +1,4 @@ +--- +category: deprecated +--- +* The member predicate `hasLocationInfo` has been deprecated on the following classes: `BasicBlock`, `Callable`, `Content`, `ContentSet`, `ControlFlow::Node`, `DataFlowCallable`, `DataFlow::Node`, `Entity`, `GVN`, `HtmlTemplate::TemplateStmt`, `IR:WriteTarget`, `SourceSinkInterpretationInput::SourceOrSinkElement`, `SourceSinkInterpretationInput::InterpretNode`, `SsaVariable`, `SsaDefinition`, `SsaWithFields`, `StringOps::ConcatenationElement`, `Type`, and `VariableWithFields`. Use `getLocation()` instead.