Skip to content

Commit 575da5c

Browse files
committed
Merge SummarizedCallable into single class
1 parent 8c4dbca commit 575da5c

File tree

1 file changed

+23
-52
lines changed

1 file changed

+23
-52
lines changed

javascript/ql/lib/semmle/javascript/frameworks/AsyncPackage.qll

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ module AsyncPackage {
1414
result = DataFlow::moduleMember("async-es", name)
1515
}
1616

17+
/**
18+
* Gets a reference to the given member or one of its `Limit` or `Series` variants.
19+
*
20+
* For example, `memberVariant("map")` finds references to `map`, `mapLimit`, and `mapSeries`.
21+
*/
22+
DataFlow::SourceNode memberVariant(string name) {
23+
result = member(name) or
24+
result = member(name + "Limit") or
25+
result = member(name + "Series")
26+
}
27+
1728
/**
1829
* Gets `Limit` or `Series` name variants for a given member name.
1930
*
2031
* For example, `memberNameVariant("map")` returns `map`, `mapLimit`, and `mapSeries`.
2132
*/
2233
bindingset[name]
23-
string memberNameVariant(string name) {
34+
private string memberNameVariant(string name) {
2435
result = name or
2536
result = name + "Limit" or
2637
result = name + "Series"
@@ -161,63 +172,23 @@ module AsyncPackage {
161172
DataFlow::FunctionNode getFinalCallback() { result = this.getCallback(finalCallbackIndex) }
162173
}
163174

164-
/**
165-
* An IterationCall with its iterator callback at index 1
166-
*/
167-
private class IterationCallCallbacksFirstArg extends IterationCall {
168-
IterationCallCallbacksFirstArg() { this.getIteratorCallbackIndex() = 1 }
169-
}
170-
171-
/**
172-
* An IterationCall with its iterator callback at index 2
173-
*/
174-
private class IterationCallCallbacksSecondArg extends IterationCall {
175-
IterationCallCallbacksSecondArg() { this.getIteratorCallbackIndex() = 2 }
176-
}
177-
178-
/**
179-
* The model with the iteratorCallbackIndex abstracted
180-
*/
181-
bindingset[iteratorCallbackIndex]
182-
private predicate iterationCallPropagatesFlow(
183-
string input, string output, boolean preservesValue, int iteratorCallbackIndex
184-
) {
185-
preservesValue = true and
186-
input = "Argument[0]." + ["ArrayElement", "SetElement", "IteratorElement", "AnyMember"] and
187-
output = "Argument[" + iteratorCallbackIndex + "].Parameter[0]"
188-
}
175+
private class IterationCallFlowSummary extends DataFlow::SummarizedCallable {
176+
private int callbackArgIndex;
189177

190-
/**
191-
* A taint step from the collection into the iterator callback (at index 1) of an iteration call.
192-
*
193-
* For example: `data -> item` in `async.each(data, (item, cb) => {})`.
194-
*/
195-
class IterationCallCallbacksFirstArgFlowSummary extends DataFlow::SummarizedCallable {
196-
IterationCallCallbacksFirstArgFlowSummary() { this = "async.[IterationCallCallbacksFirstArg]" }
197-
198-
override DataFlow::InvokeNode getACallSimple() {
199-
result instanceof IterationCallCallbacksFirstArg
178+
IterationCallFlowSummary() {
179+
this = "async.IteratorCall(callbackArgIndex=" + callbackArgIndex + ")" and
180+
callbackArgIndex in [1 .. 3]
200181
}
201182

202-
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
203-
iterationCallPropagatesFlow(input, output, preservesValue, 1)
204-
}
205-
}
206-
207-
/**
208-
* A taint step from the collection into the iterator callback (at index 2) of an iteration call.
209-
*
210-
* For example: `data -> item` in `async.eachLimit(data, 1, (item, cb) => {})`.
211-
*/
212-
class IterationCallCallbacksSecondArgFlowSummary extends DataFlow::SummarizedCallable {
213-
IterationCallCallbacksSecondArgFlowSummary() { this = "async.[IterationCallCallbackSecondArg]" }
214-
215183
override DataFlow::InvokeNode getACallSimple() {
216-
result instanceof IterationCallCallbacksSecondArg
184+
result instanceof IterationCall and
185+
result.(IterationCall).getIteratorCallbackIndex() = callbackArgIndex
217186
}
218187

219188
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
220-
iterationCallPropagatesFlow(input, output, preservesValue, 2)
189+
preservesValue = true and
190+
input = "Argument[0]." + ["ArrayElement", "SetElement", "IteratorElement", "AnyMember"] and
191+
output = "Argument[" + callbackArgIndex + "].Parameter[0]"
221192
}
222193
}
223194

@@ -248,7 +219,7 @@ module AsyncPackage {
248219
*
249220
* For example: `data -> result` in `async.sortBy(data, orderingFn, (err, result) => {})`.
250221
*/
251-
class IterationPreserveTaintStepFlowSummary extends DataFlow::SummarizedCallable {
222+
private class IterationPreserveTaintStepFlowSummary extends DataFlow::SummarizedCallable {
252223
IterationPreserveTaintStepFlowSummary() { this = "async.sortBy" }
253224

254225
override DataFlow::InvokeNode getACallSimple() {

0 commit comments

Comments
 (0)