Skip to content

Commit 7c2386b

Browse files
author
Alvaro Muñoz
committed
Simplify callable/call matches
1 parent ef549ef commit 7c2386b

File tree

1 file changed

+4
-41
lines changed

1 file changed

+4
-41
lines changed

ql/lib/codeql/actions/dataflow/internal/DataFlowPrivate.qll

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class DataFlowExpr extends Cfg::Node {
7070
}
7171

7272
/**
73-
* A call corresponds to a Uses steps where a local action, 3rd party action or a reusable workflow get called
73+
* A call corresponds to a Uses steps where a composite action or a reusable workflow get called
7474
*/
7575
class DataFlowCall instanceof Cfg::Node {
7676
DataFlowCall() { super.getAstNode() instanceof Uses }
@@ -89,46 +89,15 @@ class DataFlowCall instanceof Cfg::Node {
8989
Location getLocation() { result = this.(Cfg::Node).getLocation() }
9090
}
9191

92-
string getRepoRoot() {
93-
exists(Workflow w |
94-
w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") > 0 and
95-
result =
96-
w.getLocation()
97-
.getFile()
98-
.getRelativePath()
99-
.prefix(w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") + 1) and
100-
// exclude workflow_enum reusable workflows directory root
101-
not result.indexOf(".github/reusable_workflows/") > -1
102-
or
103-
not w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") > 0 and
104-
not w.getLocation().getFile().getRelativePath().indexOf(".github/reusable_workflows") > -1 and
105-
result = ""
106-
)
107-
}
108-
10992
/**
11093
* A Cfg scope that can be called
11194
*/
11295
class DataFlowCallable instanceof Cfg::CfgScope {
11396
string toString() { result = super.toString() }
11497

11598
string getName() {
116-
if this instanceof ReusableWorkflow
117-
then result = this.(ReusableWorkflow).getLocation().getFile().getRelativePath() // or
118-
else
119-
if this instanceof CompositeAction
120-
then
121-
result =
122-
this.(CompositeAction)
123-
.getLocation()
124-
.getFile()
125-
.getRelativePath()
126-
.prefix(this.(CompositeAction)
127-
.getLocation()
128-
.getFile()
129-
.getRelativePath()
130-
.indexOf(["/action.yml", "/action.yaml"]))
131-
else none()
99+
result = this.(ReusableWorkflowImpl).getResolvedPath() or
100+
result = this.(CompositeActionImpl).getResolvedPath()
132101
}
133102

134103
/** Gets a best-effort total ordering. */
@@ -150,13 +119,7 @@ class NormalReturn extends ReturnKind, TNormalReturn {
150119
}
151120

152121
/** Gets a viable implementation of the target of the given `Call`. */
153-
DataFlowCallable viableCallable(DataFlowCall c) {
154-
c.getName() = result.getName() or
155-
c.getName() = result.getName().replaceAll(getRepoRoot(), "") or
156-
// special case for reusable workflows downloaded by the workflow_enum action
157-
c.getName() =
158-
result.getName().replaceAll(getRepoRoot(), "").replaceAll(".github/reusable_workflows/", "")
159-
}
122+
DataFlowCallable viableCallable(DataFlowCall c) { c.getName() = result.getName() }
160123

161124
/**
162125
* Gets a node that can read the value returned from `call` with return kind

0 commit comments

Comments
 (0)