Skip to content

Commit 18a1946

Browse files
committed
JS: Factor out some big-steps
1 parent 9efa20d commit 18a1946

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,30 +1277,25 @@ module API {
12771277
boundArgs = 0 and
12781278
prop = ""
12791279
or
1280-
exists(Promisify::PromisifyCall promisify |
1281-
trackUseNode(nd, false, boundArgs, prop, t.continue()).flowsTo(promisify.getArgument(0)) and
1282-
promisified = true and
1283-
prop = "" and
1284-
result = promisify
1285-
)
1280+
promisificationBigStep(trackUseNode(nd, false, boundArgs, prop, t.continue()), result) and
1281+
promisified = true and
1282+
prop = ""
12861283
or
1287-
exists(DataFlow::PartialInvokeNode pin, DataFlow::Node pred, int predBoundArgs |
1288-
trackUseNode(nd, promisified, predBoundArgs, prop, t.continue()).flowsTo(pred) and
1289-
prop = "" and
1290-
result = pin.getBoundFunction(pred, boundArgs - predBoundArgs) and
1291-
boundArgs in [0 .. 10]
1284+
exists(DataFlow::SourceNode pred, int predBoundArgs |
1285+
pred = trackUseNode(nd, promisified, predBoundArgs, prop, t.continue()) and
1286+
partialInvocationBigStep(pred, result, boundArgs - predBoundArgs)
12921287
)
12931288
or
12941289
exists(DataFlow::SourceNode mid |
12951290
mid = trackUseNode(nd, promisified, boundArgs, prop, t) and
12961291
AdditionalUseStep::step(pragma[only_bind_out](mid), result)
12971292
)
12981293
or
1299-
exists(DataFlow::Node pred, string preprop |
1300-
trackUseNode(nd, promisified, boundArgs, preprop, t.continue()).flowsTo(pred) and
1294+
exists(DataFlow::SourceNode pred, string preprop |
1295+
pred = trackUseNode(nd, promisified, boundArgs, preprop, t.continue()) and
1296+
loadStoreBigStep(pred, result, prop) and
13011297
promisified = false and
1302-
boundArgs = 0 and
1303-
SharedTypeTrackingStep::loadStoreStep(pred, result, prop)
1298+
boundArgs = 0
13041299
|
13051300
prop = preprop
13061301
or
@@ -1310,6 +1305,28 @@ module API {
13101305
t = useStep(nd, promisified, boundArgs, prop, result)
13111306
}
13121307

1308+
pragma[nomagic]
1309+
private predicate promisificationBigStep(DataFlow::SourceNode node1, DataFlow::SourceNode node2) {
1310+
exists(Promisify::PromisifyCall promisify |
1311+
node1 = promisify.getArgument(0).getALocalSource() and
1312+
node2 = promisify
1313+
)
1314+
}
1315+
1316+
pragma[nomagic]
1317+
private predicate partialInvocationBigStep(
1318+
DataFlow::SourceNode node1, DataFlow::SourceNode node2, int boundArgs
1319+
) {
1320+
node2 = any(DataFlow::PartialInvokeNode pin).getBoundFunction(node1.getALocalUse(), boundArgs)
1321+
}
1322+
1323+
pragma[nomagic]
1324+
private predicate loadStoreBigStep(
1325+
DataFlow::SourceNode node1, DataFlow::SourceNode node2, string prop
1326+
) {
1327+
SharedTypeTrackingStep::loadStoreStep(node1.getALocalUse(), node2, prop)
1328+
}
1329+
13131330
/**
13141331
* Holds if `nd`, which is a use of an API-graph node, flows in zero or more potentially
13151332
* inter-procedural steps to some intermediate node, and then from that intermediate node to

0 commit comments

Comments
 (0)