Skip to content

Commit 7c5d58a

Browse files
committed
wip3
1 parent 9f264b5 commit 7c5d58a

1 file changed

Lines changed: 57 additions & 89 deletions

File tree

shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 57 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ module Make<
12951295
}
12961296

12971297
pragma[nomagic]
1298-
private predicate sourceOutputStateComplete(
1298+
private predicate sourceOutputStateEntry(
12991299
SourceElement source, SummaryComponentStack s, string kind, string model
13001300
) {
13011301
exists(string outSpec |
@@ -1309,13 +1309,13 @@ module Make<
13091309
SourceElement source, SummaryComponentStack s, string kind, string model
13101310
) {
13111311
exists(SummaryComponentStack exit |
1312-
sourceOutputStateComplete(source, exit, kind, model) and
1312+
sourceOutputStateEntry(source, exit, kind, model) and
13131313
s = exit.drop(_)
13141314
)
13151315
}
13161316

13171317
pragma[nomagic]
1318-
private predicate sinkInputStateComplete(
1318+
private predicate sinkInputStateEntry(
13191319
SinkElement sink, SummaryComponentStack s, string kind, string model
13201320
) {
13211321
exists(string inSpec |
@@ -1329,7 +1329,7 @@ module Make<
13291329
SinkElement sink, SummaryComponentStack s, string kind, string model
13301330
) {
13311331
exists(SummaryComponentStack entry |
1332-
sinkInputStateComplete(sink, entry, kind, model) and
1332+
sinkInputStateEntry(sink, entry, kind, model) and
13331333
s = entry.drop(_)
13341334
)
13351335
}
@@ -1507,7 +1507,7 @@ module Make<
15071507
) {
15081508
exists(SummaryComponentStack complete, SummaryComponentStack stack |
15091509
state.isSourceOutputState(source, stack, kind, model) and
1510-
sourceOutputStateComplete(source, complete, kind, model) and
1510+
sourceOutputStateEntry(source, complete, kind, model) and
15111511
stack =
15121512
min(SummaryComponentStack stack0, int i |
15131513
stack0 = complete.drop(i) and
@@ -1555,15 +1555,6 @@ module Make<
15551555
)
15561556
}
15571557

1558-
private predicate sourceOutputNode(
1559-
SourceElement source, SummaryNodeState state, SourceSinkReportingElement e, string kind,
1560-
string model
1561-
) {
1562-
sourceOutputStepNode(source, state, e, kind, model)
1563-
or
1564-
sourceOutputStoreNode(source, state, e, kind, model)
1565-
}
1566-
15671558
/**
15681559
* For a sink access path like
15691560
*
@@ -1584,7 +1575,7 @@ module Make<
15841575
) {
15851576
exists(SummaryComponentStack complete, SummaryComponentStack stack |
15861577
state.isSinkInputState(sink, stack, kind, model) and
1587-
sinkInputStateComplete(sink, complete, kind, model) and
1578+
sinkInputStateEntry(sink, complete, kind, model) and
15881579
stack =
15891580
max(SummaryComponentStack stack0, int i |
15901581
stack0 = complete.drop(i) and
@@ -1633,15 +1624,6 @@ module Make<
16331624
)
16341625
}
16351626

1636-
private predicate sinkInputNode(
1637-
SinkElement sink, SummaryNodeState state, SourceSinkReportingElement e, string kind,
1638-
string model
1639-
) {
1640-
sinkInputStepNode(sink, state, e, kind, model)
1641-
or
1642-
sinkInputReadNode(sink, state, e, kind, model)
1643-
}
1644-
16451627
private newtype TSummaryNode =
16461628
TSummaryInternalNode(SummarizedCallable c, SummaryNodeState state) {
16471629
summaryNodeRange(c, state)
@@ -1659,13 +1641,17 @@ module Make<
16591641
SourceElement source, SummaryNodeState state, SourceSinkReportingElement e, string kind,
16601642
string model
16611643
) {
1662-
sourceOutputNode(source, state, e, kind, model)
1644+
sourceOutputStepNode(source, state, e, kind, model)
1645+
or
1646+
sourceOutputStoreNode(source, state, e, kind, model)
16631647
} or
16641648
TSinkInputNode(
16651649
SinkElement sink, SummaryNodeState state, SourceSinkReportingElement e, string kind,
16661650
string model
16671651
) {
1668-
sinkInputNode(sink, state, e, kind, model)
1652+
sinkInputStepNode(sink, state, e, kind, model)
1653+
or
1654+
sinkInputReadNode(sink, state, e, kind, model)
16691655
}
16701656

16711657
abstract class SummaryNode extends TSummaryNode {
@@ -1774,42 +1760,33 @@ module Make<
17741760
SourceOutputNode() { this = TSourceOutputNode(source_, state_, e_, kind_, model_) }
17751761

17761762
/**
1777-
* Holds if this node is an entry node, i.e. before any stores have been performed.
1763+
* Holds if this node is an entry node, i.e. before any stores or steps have been
1764+
* performed.
17781765
*
17791766
* This node should be used as the actual source node in data flow configurations.
17801767
*/
17811768
predicate isEntry(string kind, string model) {
17821769
model = model_ and
1783-
exists(SummaryComponentStack out |
1784-
state_.isSourceOutputState(source_, out, kind, model_) and
1785-
sourceOutputStateComplete(source_, out, kind, model_)
1770+
exists(SummaryComponentStack stack |
1771+
state_.isSourceOutputState(source_, stack, kind, model_) and
1772+
sourceOutputStateEntry(source_, stack, kind, model_)
17861773
)
17871774
}
17881775

17891776
/**
1790-
* Holds if this node is an exit node, i.e. after all stores have been performed.
1777+
* Holds if this node is an exit node, i.e. after all stores and steps have been
1778+
* performed.
17911779
*
1792-
* A local flow step should be added from this node to a data flow node representing
1793-
* `s` inside `source`.
1780+
* A flow step is added from this node to a data flow node representing
1781+
* `s` inside `source`, using `getSourceExitNode`.
17941782
*/
17951783
predicate isExit(
17961784
SourceElement source, SummaryComponent sc, SourceSinkReportingElement e, string model
17971785
) {
1798-
exists(SummaryComponentStack stack |
1799-
source = source_ and
1800-
model = model_ and
1801-
state_.isSourceOutputState(source, stack, _, model) and
1802-
e = e_ and
1803-
stack = TSingletonSummaryComponentStack(sc)
1804-
// sourceOutputStateExit(source, stack, kind_, model) and
1805-
// sc =
1806-
// min(SummaryComponent sc0, int i |
1807-
// sc0 = stack.drop(i).head() and
1808-
// not sc0 instanceof TContentSummaryComponent
1809-
// |
1810-
// sc0 order by i
1811-
// )
1812-
)
1786+
source = source_ and
1787+
model = model_ and
1788+
state_.isSourceOutputState(source, TSingletonSummaryComponentStack(sc), _, model) and
1789+
e = e_
18131790
}
18141791

18151792
override predicate isHidden() {
@@ -1849,10 +1826,11 @@ module Make<
18491826
SinkInputNode() { this = TSinkInputNode(sink_, state_, e_, kind_, model_) }
18501827

18511828
/**
1852-
* Holds if this node is an entry node, i.e. before any reads have been performed.
1829+
* Holds if this node is an entry node, i.e. before any reads and steps have been
1830+
* performed.
18531831
*
1854-
* A local flow step should be added to this node from a data flow node representing
1855-
* `sc` inside `sink`.
1832+
* A flow step is added to this node from a data flow node representing
1833+
* `sc` inside `sink`, using `getSinkEntryNode`.
18561834
*/
18571835
predicate isEntry(
18581836
SinkElement sink, SummaryComponent sc, SourceSinkReportingElement e, string model
@@ -1861,20 +1839,15 @@ module Make<
18611839
model = model_ and
18621840
e = e_ and
18631841
exists(SummaryComponentStack stack |
1864-
sinkInputStateComplete(sink, stack, kind_, model) and
1842+
sinkInputStateEntry(sink, stack, kind_, model) and
18651843
state_.isSinkInputState(sink, stack, _, model) and
18661844
sc = stack.head()
1867-
// min(SummaryComponent sc0, int i |
1868-
// sc0 = stack.drop(i).head() and
1869-
// not sc0 instanceof TContentSummaryComponent
1870-
// |
1871-
// sc0 order by i
1872-
// )
18731845
)
18741846
}
18751847

18761848
/**
1877-
* Holds if this node is an exit node, i.e. after all reads have been performed.
1849+
* Holds if this node is an exit node, i.e. after all reads and steps have been
1850+
* performed.
18781851
*
18791852
* This node should be used as the actual sink node in data flow configurations.
18801853
*/
@@ -2306,15 +2279,9 @@ module Make<
23062279
or
23072280
exists(SummaryNode succSummary |
23082281
succSummary = StepsInput::getSummaryNode(succ) and
2282+
sinkEntryStep(pred, succSummary, true) and
23092283
preservesValue = true and
23102284
model = ""
2311-
|
2312-
sinkEntryStep(pred, succSummary, true)
2313-
// or
2314-
// exists(SummaryComponent sc, SourceSinkReportingElement e |
2315-
// pred = getSinkEntryNode(e, sc) and
2316-
// succSummary.(SinkInputNode).isEntry(_, sc, e, _)
2317-
// )
23182285
)
23192286
or
23202287
exists(FlowSummaryCallBase summaryCall, ReturnKind rk, SummarizedCallable sc |
@@ -2332,37 +2299,38 @@ module Make<
23322299

23332300
/**
23342301
* Holds if there is a read step of content `c` from `pred` to `succ`, which
2335-
* is synthesized from a flow summary.
2302+
* is synthesized from a flow summary or a sink specification.
23362303
*/
23372304
predicate summaryReadStep(SummaryNode pred, ContentSet c, SummaryNode succ) {
2338-
exists(SummarizedCallable sc, SummaryComponentStack s |
2339-
pred = summaryNodeInputState(sc, s.tail()) and
2340-
succ = summaryNodeInputState(sc, s) and
2341-
SummaryComponent::content(c) = s.head()
2342-
)
2343-
or
2344-
exists(SinkElement sink, SourceSinkReportingElement e, SummaryComponentStack s |
2345-
pred = sinkElementInputState(sink, e, s) and
2346-
succ = sinkElementInputState(sink, e, s.tail()) and
2347-
SummaryComponent::content(c) = s.tail().head() // todo
2305+
exists(SummaryComponentStack stack | SummaryComponent::content(c) = stack.head() |
2306+
exists(SummarizedCallable sc |
2307+
pred = summaryNodeInputState(sc, stack.tail()) and
2308+
succ = summaryNodeInputState(sc, stack)
2309+
)
2310+
or
2311+
exists(SinkElement sink, SourceSinkReportingElement e, SummaryComponentStack stack0 |
2312+
pred = sinkElementInputState(sink, e, stack0) and
2313+
stack = stack0.tail() and
2314+
succ = sinkElementInputState(sink, e, stack)
2315+
)
23482316
)
23492317
}
23502318

23512319
/**
23522320
* Holds if there is a store step of content `c` from `pred` to `succ`, which
2353-
* is synthesized from a flow summary.
2321+
* is synthesized from a flow summary or a source specification.
23542322
*/
23552323
predicate summaryStoreStep(SummaryNode pred, ContentSet c, SummaryNode succ) {
2356-
exists(SummarizedCallable sc, SummaryComponentStack s |
2357-
pred = summaryNodeOutputState(sc, s) and
2358-
succ = summaryNodeOutputState(sc, s.tail()) and
2359-
SummaryComponent::content(c) = s.head()
2360-
)
2361-
or
2362-
exists(SourceElement source, SourceSinkReportingElement e, SummaryComponentStack s |
2363-
pred = sourceElementOutputState(source, e, s) and
2364-
succ = sourceElementOutputState(source, e, s.tail()) and
2365-
SummaryComponent::content(c) = s.head()
2324+
exists(SummaryComponentStack stack | SummaryComponent::content(c) = stack.head() |
2325+
exists(SummarizedCallable sc |
2326+
pred = summaryNodeOutputState(sc, stack) and
2327+
succ = summaryNodeOutputState(sc, stack.tail())
2328+
)
2329+
or
2330+
exists(SourceElement source, SourceSinkReportingElement e |
2331+
pred = sourceElementOutputState(source, e, stack) and
2332+
succ = sourceElementOutputState(source, e, stack.tail())
2333+
)
23662334
)
23672335
}
23682336

@@ -2390,7 +2358,7 @@ module Make<
23902358
succSummary = TSourceOutputNode(source, state, e, kind, model)
23912359
)
23922360
or
2393-
// We model all non-store steps as jumps in order to ensure that they are not stepped
2361+
// We model all non-read steps as jumps in order to ensure that they are not stepped
23942362
// over in the path graph.
23952363
exists(
23962364
SinkElement sink, string kind, SummaryNodeState state, SummaryNodeState state0,

0 commit comments

Comments
 (0)