Skip to content

Commit

Permalink
Merge branch 'main' into redsun82/pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed May 29, 2024
2 parents 336ec08 + 7756259 commit 1e6820b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ class DataFlowCallable extends TDataFlowCallable {
.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())
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
Expand All @@ -322,6 +329,13 @@ class DataFlowCallable extends TDataFlowCallable {
}
}

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;
Expand All @@ -344,6 +358,9 @@ class DataFlowCall extends Expr {
not exists(this.getEnclosingFunction()) and result.asFileScope() = this.getFile()
}

/** Gets the location of this call. */
Location getLocation() { result = super.getLocation() }

/** Gets a best-effort total ordering. */
int totalorder() {
this =
Expand Down
6 changes: 6 additions & 0 deletions shared/dataflow/codeql/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ signature module InputSig<LocationSig Location> {
/** Gets a textual representation of this element. */
string toString();

/** Gets the location of this call. */
Location getLocation();

DataFlowCallable getEnclosingCallable();

/** Gets a best-effort total ordering. */
Expand All @@ -82,6 +85,9 @@ signature module InputSig<LocationSig Location> {
/** Gets a textual representation of this element. */
string toString();

/** Gets the location of this callable. */
Location getLocation();

/** Gets a best-effort total ordering. */
int totalorder();
}
Expand Down
11 changes: 6 additions & 5 deletions shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -3370,18 +3370,19 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
Location getLocation() { result = p.getLocation() }
}

pragma[nomagic]
private predicate stage5ConsCand(Content c, DataFlowType t, AccessPathFront apf, int len) {
Stage5::consCand(c, t, any(AccessPathApprox ap | ap.getFront() = apf and ap.len() = len - 1))
}

/**
* Gets the number of length 2 access path approximations that correspond to `apa`.
*/
private int count1to2unfold(AccessPathApproxCons1 apa) {
exists(Content c, int len |
c = apa.getHead() and
len = apa.len() and
result =
strictcount(DataFlowType t, AccessPathFront apf |
Stage5::consCand(c, t,
any(AccessPathApprox ap | ap.getFront() = apf and ap.len() = len - 1))
)
result = strictcount(DataFlowType t, AccessPathFront apf | stage5ConsCand(c, t, apf, len))
)
}

Expand Down

0 comments on commit 1e6820b

Please sign in to comment.