Skip to content

Commit 94f110f

Browse files
aschackmullhvitved
authored andcommitted
Sync.
1 parent b4ecfae commit 94f110f

20 files changed

Lines changed: 600 additions & 1100 deletions

File tree

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ private class AccessPathApproxOption extends TAccessPathApproxOption {
16451645
}
16461646

16471647
/**
1648-
* Holds if `node` is reachable with approximate access path `ap` from a source
1648+
* Holds if `node` is reachable with approximate access path `apa` from a source
16491649
* in the configuration `config`.
16501650
*
16511651
* The call context `cc` records whether the node is reached through an
@@ -1863,7 +1863,7 @@ private predicate flowFwdIsEntered(
18631863
}
18641864

18651865
/**
1866-
* Holds if `node` with approximate access path `ap` is part of a path from a
1866+
* Holds if `node` with approximate access path `apa` is part of a path from a
18671867
* source to a sink in the configuration `config`.
18681868
*
18691869
* The Boolean `toReturn` records whether the node must be returned from
@@ -2098,26 +2098,22 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20982098

20992099
private newtype TAccessPath =
21002100
TAccessPathNil(DataFlowType t) or
2101-
TAccessPathCons(TypedContent head, AccessPath tail) { pathStoreStep(_, _, tail, _, head, _) }
2101+
TAccessPathCons(TypedContent head, AccessPath tail) { flowConsCand(head, tail.getApprox(), _) }
21022102

21032103
private newtype TPathNode =
2104-
TPathNodeMid(
2105-
Node node, CallContext cc, SummaryCtx sc, AccessPath ap, AccessPathApprox apa,
2106-
Configuration config
2107-
) {
2104+
TPathNodeMid(Node node, CallContext cc, SummaryCtx sc, AccessPath ap, Configuration config) {
21082105
// A PathNode is introduced by a source ...
21092106
flow(node, config) and
21102107
config.isSource(node) and
21112108
cc instanceof CallContextAny and
21122109
sc instanceof SummaryCtxNone and
2113-
ap = TAccessPathNil(getNodeType(node)) and
2114-
apa = TNil(getNodeType(node))
2110+
ap = TAccessPathNil(getNodeType(node))
21152111
or
21162112
// ... or a step from an existing PathNode to another node.
21172113
exists(PathNodeMid mid |
2118-
pathStep(mid, node, cc, sc, ap, apa) and
2114+
pathStep(mid, node, cc, sc, ap) and
21192115
config = mid.getConfiguration() and
2120-
flow(node, _, _, apa, unbind(config))
2116+
flow(node, _, _, ap.getApprox(), unbind(config))
21212117
)
21222118
} or
21232119
TPathNodeSink(Node node, Configuration config) {
@@ -2129,7 +2125,7 @@ private newtype TPathNode =
21292125
or
21302126
// ... or a sink that can be reached from a source
21312127
exists(PathNodeMid mid |
2132-
pathStep(mid, node, _, _, _, TNil(_)) and
2128+
pathStep(mid, node, _, _, TAccessPathNil(_)) and
21332129
config = unbind(mid.getConfiguration())
21342130
)
21352131
)
@@ -2142,9 +2138,6 @@ private newtype TPathNode =
21422138
* tracked object. The final type indicates the type of the tracked object.
21432139
*/
21442140
abstract private class AccessPath extends TAccessPath {
2145-
/** Gets the type of this access path. */
2146-
abstract DataFlowType getType();
2147-
21482141
/** Gets the head of this access path, if any. */
21492142
abstract TypedContent getHead();
21502143

@@ -2178,7 +2171,7 @@ private class AccessPathNil extends AccessPath, TAccessPathNil {
21782171

21792172
AccessPathNil() { this = TAccessPathNil(t) }
21802173

2181-
override DataFlowType getType() { result = t }
2174+
DataFlowType getType() { result = t }
21822175

21832176
override TypedContent getHead() { none() }
21842177

@@ -2199,8 +2192,6 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
21992192

22002193
AccessPathCons() { this = TAccessPathCons(head, tail) }
22012194

2202-
override DataFlowType getType() { result = tail.getType() }
2203-
22042195
override TypedContent getHead() { result = head }
22052196

22062197
override AccessPath getTail() { result = tail }
@@ -2216,14 +2207,16 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
22162207
override int length() { result = 1 + tail.length() }
22172208

22182209
private string toStringImpl() {
2219-
tail = TAccessPathNil(_) and
2220-
result = head.toString()
2210+
exists(DataFlowType t |
2211+
tail = TAccessPathNil(t) and
2212+
result = head.toString() + "]" + concat(" : " + ppReprType(t))
2213+
)
22212214
or
22222215
result = head + ", " + tail.(AccessPathCons).toStringImpl()
22232216
}
22242217

22252218
override string toString() {
2226-
result = "[" + this.toStringImpl() + "]" + concat(" : " + ppReprType(this.getType()))
2219+
result = "[" + this.toStringImpl()
22272220
}
22282221
}
22292222

@@ -2340,10 +2333,9 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
23402333
CallContext cc;
23412334
SummaryCtx sc;
23422335
AccessPath ap;
2343-
AccessPathApprox apa;
23442336
Configuration config;
23452337

2346-
PathNodeMid() { this = TPathNodeMid(node, cc, sc, ap, apa, config) }
2338+
PathNodeMid() { this = TPathNodeMid(node, cc, sc, ap, config) }
23472339

23482340
override Node getNode() { result = node }
23492341

@@ -2353,13 +2345,10 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
23532345

23542346
AccessPath getAp() { result = ap }
23552347

2356-
AccessPathApprox getApa() { result = apa }
2357-
23582348
override Configuration getConfiguration() { result = config }
23592349

23602350
private PathNodeMid getSuccMid() {
2361-
pathStep(this, result.getNode(), result.getCallContext(), result.getSummaryCtx(),
2362-
result.getAp(), _) and
2351+
pathStep(this, result.getNode(), result.getCallContext(), result.getSummaryCtx(), result.getAp()) and
23632352
result.getConfiguration() = unbind(this.getConfiguration())
23642353
}
23652354

@@ -2371,7 +2360,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
23712360
exists(PathNodeMid mid, PathNodeSink sink |
23722361
mid = getSuccMid() and
23732362
mid.getNode() = sink.getNode() and
2374-
mid.getApa() instanceof AccessPathApproxNil and
2363+
mid.getAp() instanceof AccessPathNil and
23752364
sink.getConfiguration() = unbind(mid.getConfiguration()) and
23762365
result = sink
23772366
)
@@ -2381,7 +2370,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
23812370
config.isSource(node) and
23822371
cc instanceof CallContextAny and
23832372
sc instanceof SummaryCtxNone and
2384-
apa instanceof AccessPathApproxNil
2373+
ap instanceof AccessPathNil
23852374
}
23862375
}
23872376

@@ -2409,33 +2398,22 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
24092398
* Holds if data may flow from `mid` to `node`. The last step in or out of
24102399
* a callable is recorded by `cc`.
24112400
*/
2412-
private predicate pathStep(
2413-
PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap, AccessPathApprox apa
2414-
) {
2401+
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
24152402
pathStepSameAp(mid, node, cc, sc) and
2416-
ap = mid.getAp() and
2417-
apa = mid.getApa()
2403+
ap = mid.getAp()
24182404
or
24192405
exists(DataFlowType t |
24202406
pathStepEmptyAp(mid, node, cc, sc, t) and
2421-
ap = TAccessPathNil(t) and
2422-
apa = TNil(t)
2407+
ap = TAccessPathNil(t)
24232408
)
24242409
or
2425-
exists(TypedContent tc, AccessPathApprox apa0 |
2426-
pathStoreStep(mid, node, ap.pop(tc), apa0, tc, cc) and
2427-
// Same as `apa = ap.getApprox()`, but avoids mutual recursion
2428-
apa0 = apa.pop(tc)
2429-
) and
2410+
exists(TypedContent tc | pathStoreStep(mid, node, ap.pop(tc), tc, cc)) and
24302411
sc = mid.getSummaryCtx()
24312412
or
24322413
exists(TypedContent tc | pathReadStep(mid, node, ap.push(tc), tc, cc)) and
2433-
sc = mid.getSummaryCtx() and
2434-
// Here the approximation cannot be created from the approximation before
2435-
// the read, so we must use `getApprox()`
2436-
apa = ap.getApprox()
2414+
sc = mid.getSummaryCtx()
24372415
or
2438-
pathThroughCallable(mid, node, cc, ap, apa) and
2416+
pathThroughCallable(mid, node, cc, ap) and
24392417
sc = mid.getSummaryCtx()
24402418
}
24412419

@@ -2504,10 +2482,9 @@ private predicate storeCand(Node node1, TypedContent tc, Node node2, Configurati
25042482

25052483
pragma[nomagic]
25062484
private predicate pathStoreStep(
2507-
PathNodeMid mid, Node node, AccessPath ap0, AccessPathApprox apa0, TypedContent tc, CallContext cc
2485+
PathNodeMid mid, Node node, AccessPath ap0, TypedContent tc, CallContext cc
25082486
) {
25092487
ap0 = mid.getAp() and
2510-
apa0 = mid.getApa() and
25112488
storeCand(mid.getNode(), tc, node, mid.getConfiguration()) and
25122489
cc = mid.getCallContext()
25132490
}
@@ -2519,7 +2496,7 @@ private predicate pathOutOfCallable0(
25192496
pos = getReturnPosition(mid.getNode()) and
25202497
innercc = mid.getCallContext() and
25212498
innercc instanceof CallContextNoCall and
2522-
apa = mid.getApa() and
2499+
apa = mid.getAp().getApprox() and
25232500
config = mid.getConfiguration()
25242501
}
25252502

@@ -2570,7 +2547,7 @@ private predicate pathIntoArg(
25702547
cc = mid.getCallContext() and
25712548
arg.argumentOf(call, i) and
25722549
ap = mid.getAp() and
2573-
apa = mid.getApa()
2550+
apa = ap.getApprox()
25742551
)
25752552
}
25762553

@@ -2653,7 +2630,7 @@ private predicate paramFlowsThrough(
26532630
sc = mid.getSummaryCtx() and
26542631
config = mid.getConfiguration() and
26552632
ap = mid.getAp() and
2656-
apa = mid.getApa() and
2633+
apa = ap.getApprox() and
26572634
pos = sc.getParameterPos() and
26582635
not kind.(ParamUpdateReturnKind).getPosition() = pos
26592636
)
@@ -2675,10 +2652,8 @@ private predicate pathThroughCallable0(
26752652
* The context `cc` is restored to its value prior to entering the callable.
26762653
*/
26772654
pragma[noinline]
2678-
private predicate pathThroughCallable(
2679-
PathNodeMid mid, Node out, CallContext cc, AccessPath ap, AccessPathApprox apa
2680-
) {
2681-
exists(DataFlowCall call, ReturnKindExt kind |
2655+
private predicate pathThroughCallable(PathNodeMid mid, Node out, CallContext cc, AccessPath ap) {
2656+
exists(DataFlowCall call, ReturnKindExt kind, AccessPathApprox apa |
26822657
pathThroughCallable0(call, mid, kind, cc, ap, apa) and
26832658
out = getAnOutNodeFlow(kind, call, apa, unbind(mid.getConfiguration()))
26842659
)

0 commit comments

Comments
 (0)