Java/Shared: Use getLocation instead of hasLocationInfo.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-03-20 14:29:48 +00:00
parent 2fd57f6ee7
commit 90fbacc7bf
3 changed files with 13 additions and 24 deletions

View File

@@ -14,7 +14,7 @@ private import semmle.code.java.dataflow.internal.BaseSSA
private import semmle.code.java.controlflow.Guards
private import codeql.typeflow.TypeFlow
private module Input implements TypeFlowInput {
private module Input implements TypeFlowInput<J::Location> {
private newtype TTypeFlowNode =
TField(Field f) { not f.getType() instanceof PrimitiveType } or
TSsa(BaseSsaVariable ssa) { not ssa.getSourceVariable().getType() instanceof PrimitiveType } or
@@ -38,12 +38,6 @@ private module Input implements TypeFlowInput {
result = this.asMethod().toString()
}
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
Location getLocation() {
result = this.asField().getLocation() or
result = this.asSsa().getLocation() or
@@ -164,7 +158,7 @@ private module Input implements TypeFlowInput {
*/
pragma[nomagic]
private predicate upcastCand(TypeFlowNode n, RefType t1, RefType t1e, RefType t2, RefType t2e) {
exists(TypeFlowNode next | step(n, next) or Make<Input>::joinStep(n, next) |
exists(TypeFlowNode next | step(n, next) or Make<J::Location, Input>::joinStep(n, next) |
n.getType() = t1 and
next.getType() = t2 and
t1.getErasure() = t1e and
@@ -356,7 +350,7 @@ private module Input implements TypeFlowInput {
cached
private module TypeFlowBounds {
private module TypeFlow = Make<Input>;
private module TypeFlow = Make<J::Location, Input>;
/**
* Holds if the runtime type of `f` is bounded by `t` and if this bound is

View File

@@ -8,8 +8,10 @@
* explicit or implicit cast that lost type information.
*/
private import codeql.util.Location
/** Provides the input specification. */
signature module TypeFlowInput {
signature module TypeFlowInput<LocationSig Location> {
/**
* A node for which type information is available. For example, expressions
* and method declarations.
@@ -21,16 +23,8 @@ signature module TypeFlowInput {
/** Gets the type of this node. */
Type getType();
/**
* 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
);
/** Gets the location of this node. */
Location getLocation();
}
/**
@@ -112,6 +106,6 @@ private import internal.TypeFlowImpl as Impl
/**
* Provides an implementation of type-flow using input `I`.
*/
module Make<TypeFlowInput I> {
import Impl::TypeFlow<I>
module Make<LocationSig Location, TypeFlowInput<Location> I> {
import Impl::TypeFlow<Location, I>
}

View File

@@ -1,7 +1,8 @@
private import codeql.typeflow.TypeFlow
private import codeql.util.Location
private import codeql.util.Unit
module TypeFlow<TypeFlowInput I> {
module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
private import I
/**
@@ -56,7 +57,7 @@ module TypeFlow<TypeFlowInput I> {
n1 =
rank[r](TypeFlowNode n, int startline, int startcolumn |
edge(n, n2) and
n.hasLocationInfo(_, startline, startcolumn, _, _)
n.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
n order by startline, startcolumn
)