Skip to content

Commit 8d471f0

Browse files
author
Max Schaefer
committed
JavaScript: Simplify a few helper predicates.
1 parent 017ae49 commit 8d471f0

File tree

3 files changed

+28
-46
lines changed

3 files changed

+28
-46
lines changed

javascript/ql/src/semmle/javascript/dataflow/Configuration.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,19 @@ private predicate basicFlowStep(DataFlow::Node pred, DataFlow::Node succ, PathSu
422422
or
423423
// Flow through properties of objects
424424
propertyFlowStep(pred, succ) and
425-
summary = PathSummary::level(true)
425+
summary = PathSummary::level()
426426
or
427427
// Flow through global variables
428428
globalFlowStep(pred, succ) and
429-
summary = PathSummary::level(true)
429+
summary = PathSummary::level()
430430
or
431431
// Flow into function
432432
callStep(pred, succ) and
433-
summary = PathSummary::call(true)
433+
summary = PathSummary::call()
434434
or
435435
// Flow out of function
436436
returnStep(pred, succ) and
437-
summary = PathSummary::return(true)
437+
summary = PathSummary::return()
438438
)
439439
}
440440

@@ -540,7 +540,7 @@ private predicate reachableFromInput(Function f, DataFlow::Node invk,
540540
DataFlow::Node input, DataFlow::Node nd,
541541
DataFlow::Configuration cfg, PathSummary summary) {
542542
callInputStep(f, invk, input, nd, cfg) and
543-
summary = PathSummary::empty()
543+
summary = PathSummary::level()
544544
or
545545
exists (DataFlow::Node mid, PathSummary oldSummary, PathSummary newSummary |
546546
reachableFromInput(f, invk, input, mid, cfg, oldSummary) and
@@ -571,7 +571,7 @@ private predicate flowThroughCall(DataFlow::Node input, DataFlow::Node invk,
571571
private predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop,
572572
DataFlow::Configuration cfg, PathSummary summary) {
573573
basicStoreStep(pred, succ, prop) and
574-
summary = PathSummary::level(true)
574+
summary = PathSummary::level()
575575
or
576576
exists (Function f, DataFlow::Node mid, DataFlow::SourceNode base |
577577
// `f` stores its parameter `pred` in property `prop` of a value that it returns,
@@ -677,7 +677,7 @@ private predicate onPath(DataFlow::Node nd, DataFlow::Configuration cfg,
677677
reachableFromSource(nd, cfg, summary1) and
678678
isSink(nd, cfg, summary1.getEndLabel()) and
679679
not cfg.isBarrier(nd) and
680-
summary2 = PathSummary::empty()
680+
summary2 = PathSummary::level()
681681
or
682682
exists (DataFlow::Node mid, PathSummary newSummary, PathSummary oldSummary |
683683
onPath(mid, cfg, _, oldSummary) and

javascript/ql/src/semmle/javascript/dataflow/TrackedNodes.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ private module NodeTracking {
7070
(
7171
// Local flow
7272
localFlowStep(pred, succ) and
73-
summary = PathSummary::level(true)
73+
summary = PathSummary::level()
7474
or
7575
// Flow through properties of objects
7676
propertyFlowStep(pred, succ) and
77-
summary = PathSummary::level(true)
77+
summary = PathSummary::level()
7878
or
7979
// Flow through global variables
8080
globalFlowStep(pred, succ) and
81-
summary = PathSummary::level(true)
81+
summary = PathSummary::level()
8282
or
8383
// Flow into function
8484
callStep(pred, succ) and
85-
summary = PathSummary::call(true)
85+
summary = PathSummary::call()
8686
or
8787
// Flow out of function
8888
returnStep(pred, succ) and
89-
summary = PathSummary::return(true)
89+
summary = PathSummary::return()
9090
)
9191
}
9292

@@ -138,7 +138,7 @@ private module NodeTracking {
138138
DataFlow::Node input, DataFlow::Node nd,
139139
PathSummary summary) {
140140
callInputStep(f, invk, input, nd) and
141-
summary = PathSummary::empty()
141+
summary = PathSummary::level()
142142
or
143143
exists (DataFlow::Node mid, PathSummary oldSummary, PathSummary newSummary |
144144
reachableFromInput(f, invk, input, mid, oldSummary) and
@@ -165,7 +165,7 @@ private module NodeTracking {
165165
private predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop,
166166
PathSummary summary) {
167167
basicStoreStep(pred, succ, prop) and
168-
summary = PathSummary::level(true)
168+
summary = PathSummary::level()
169169
or
170170
exists (Function f, DataFlow::Node mid, DataFlow::SourceNode base |
171171
// `f` stores its parameter `pred` in property `prop` of a value that it returns,
@@ -214,7 +214,7 @@ private module NodeTracking {
214214
// Flow through a function that returns a value that depends on one of its arguments
215215
// or a captured variable
216216
flowThroughCall(pred, succ) and
217-
summary = PathSummary::level(true)
217+
summary = PathSummary::level()
218218
or
219219
// Flow through a property write/read pair
220220
flowThroughProperty(pred, succ, summary)
@@ -226,7 +226,7 @@ private module NodeTracking {
226226
*/
227227
predicate flowsTo(TrackedNode source, DataFlow::Node nd, PathSummary summary) {
228228
source = nd and
229-
summary = PathSummary::empty()
229+
summary = PathSummary::level()
230230
or
231231
exists (DataFlow::Node pred, PathSummary oldSummary, PathSummary newSummary |
232232
flowsTo(source, pred, oldSummary) and

javascript/ql/src/semmle/javascript/dataflow/internal/FlowSteps.qll

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -322,48 +322,30 @@ class PathSummary extends TPathSummary {
322322
}
323323

324324
module PathSummary {
325-
/**
326-
* Gets a summary describing an empty path.
327-
*/
328-
PathSummary empty() {
329-
result = level(true)
330-
}
331-
332-
private PathSummary mkPathSummary(boolean hasCall, boolean hasReturn, Boolean valuePreserving) {
333-
exists (FlowLabel start, FlowLabel end |
334-
if valuePreserving = false then
335-
end = FlowLabel::taint()
336-
else
337-
start = end
338-
|
339-
result = MkPathSummary(hasCall, hasReturn, start, end)
340-
)
341-
}
342-
343325
/**
344326
* Gets a summary describing a path without any calls or returns.
345-
* `valuePreserving` indicates whether the path preserves the value of its
346-
* start node or only its taintedness.
347327
*/
348-
PathSummary level(Boolean valuePreserving) {
349-
result = mkPathSummary(false, false, valuePreserving)
328+
PathSummary level() {
329+
exists (FlowLabel lbl |
330+
result = MkPathSummary(false, false, lbl, lbl)
331+
)
350332
}
351333

352334
/**
353335
* Gets a summary describing a path with one or more calls, but no returns.
354-
* `valuePreserving` indicates whether the path preserves the value of its
355-
* start node or only its taintedness.
356336
*/
357-
PathSummary call(Boolean valuePreserving) {
358-
result = mkPathSummary(false, true, valuePreserving)
337+
PathSummary call() {
338+
exists (FlowLabel lbl |
339+
result = MkPathSummary(false, true, lbl, lbl)
340+
)
359341
}
360342

361343
/**
362344
* Gets a summary describing a path with one or more returns, but no calls.
363-
* `valuePreserving` indicates whether the path preserves the value of its
364-
* start node or only its taintedness.
365345
*/
366-
PathSummary return(Boolean valuePreserving) {
367-
result = mkPathSummary(true, false, valuePreserving)
346+
PathSummary return() {
347+
exists (FlowLabel lbl |
348+
result = MkPathSummary(true, false, lbl, lbl)
349+
)
368350
}
369351
}

0 commit comments

Comments
 (0)