Skip to content

Commit 1cd582c

Browse files
committed
Data flow: Remove allowParameterReturnInSelf restriction
1 parent 4bf63fe commit 1cd582c

File tree

14 files changed

+4
-203
lines changed

14 files changed

+4
-203
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll

-9
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,6 @@ predicate knownSinkModel(Node sink, string model) { none() }
296296

297297
class DataFlowSecondLevelScope = Unit;
298298

299-
/**
300-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
301-
* side-effect, resulting in a summary from `p` to itself.
302-
*
303-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
304-
* by default as a heuristic.
305-
*/
306-
predicate allowParameterReturnInSelf(ParameterNode p) { none() }
307-
308299
/** An approximated `Content`. */
309300
class ContentApprox = Unit;
310301

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

-17
Original file line numberDiff line numberDiff line change
@@ -1342,23 +1342,6 @@ predicate knownSourceModel(Node source, string model) { External::sourceNode(sou
13421342

13431343
predicate knownSinkModel(Node sink, string model) { External::sinkNode(sink, _, model) }
13441344

1345-
/**
1346-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
1347-
* side-effect, resulting in a summary from `p` to itself.
1348-
*
1349-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
1350-
* by default as a heuristic.
1351-
*/
1352-
predicate allowParameterReturnInSelf(ParameterNode p) {
1353-
p instanceof IndirectParameterNode
1354-
or
1355-
// models-as-data summarized flow
1356-
exists(DataFlowCallable c, ParameterPosition pos |
1357-
p.isParameterOf(c, pos) and
1358-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
1359-
)
1360-
}
1361-
13621345
private predicate fieldHasApproxName(Field f, string s) {
13631346
s = f.getName().charAt(0) and
13641347
// Reads and writes of union fields are tracked using `UnionContent`.

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

-17
Original file line numberDiff line numberDiff line change
@@ -3084,23 +3084,6 @@ predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
30843084

30853085
class DataFlowSecondLevelScope = Unit;
30863086

3087-
/**
3088-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
3089-
* side-effect, resulting in a summary from `p` to itself.
3090-
*
3091-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
3092-
* by default as a heuristic.
3093-
*/
3094-
predicate allowParameterReturnInSelf(ParameterNode p) {
3095-
exists(DataFlowCallable c, ParameterPosition pos |
3096-
parameterNode(p, c, pos) and
3097-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
3098-
)
3099-
or
3100-
VariableCapture::Flow::heuristicAllowInstanceParameterReturnInSelf(p.(DelegateSelfReferenceNode)
3101-
.getCallable())
3102-
}
3103-
31043087
/** An approximated `Content`. */
31053088
class ContentApprox extends TContentApprox {
31063089
/** Gets a textual representation of this approximated `Content`. */

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

-14
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,6 @@ predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
438438

439439
class DataFlowSecondLevelScope = Unit;
440440

441-
/**
442-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
443-
* side-effect, resulting in a summary from `p` to itself.
444-
*
445-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
446-
* by default as a heuristic.
447-
*/
448-
predicate allowParameterReturnInSelf(ParameterNode p) {
449-
exists(DataFlowCallable c, int pos |
450-
p.isParameterOf(c, pos) and
451-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
452-
)
453-
}
454-
455441
/** An approximated `Content`. */
456442
class ContentApprox = Unit;
457443

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

-16
Original file line numberDiff line numberDiff line change
@@ -695,22 +695,6 @@ private Expr getRelatedExpr(Node n) {
695695
/** Gets the second-level scope containing the node `n`, if any. */
696696
DataFlowSecondLevelScope getSecondLevelScope(Node n) { result.getANode() = n }
697697

698-
/**
699-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
700-
* side-effect, resulting in a summary from `p` to itself.
701-
*
702-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
703-
* by default as a heuristic.
704-
*/
705-
predicate allowParameterReturnInSelf(ParameterNode p) {
706-
exists(DataFlowCallable c, ParameterPosition pos |
707-
parameterNode(p, c, pos) and
708-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
709-
)
710-
or
711-
CaptureFlow::heuristicAllowInstanceParameterReturnInSelf(p.(InstanceParameterNode).getCallable())
712-
}
713-
714698
/** An approximated `Content`. */
715699
class ContentApprox extends TContentApprox {
716700
/** Gets a textual representation of this approximated `Content`. */

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

-19
Original file line numberDiff line numberDiff line change
@@ -1096,25 +1096,6 @@ predicate knownSinkModel(Node sink, string model) {
10961096

10971097
class DataFlowSecondLevelScope = Unit;
10981098

1099-
/**
1100-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
1101-
* side-effect, resulting in a summary from `p` to itself.
1102-
*
1103-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
1104-
* by default as a heuristic.
1105-
*/
1106-
predicate allowParameterReturnInSelf(ParameterNode p) {
1107-
exists(DataFlowCallable c, ParameterPosition pos |
1108-
p.(ParameterNodeImpl).isParameterOf(c, pos) and
1109-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asLibraryCallable(), pos)
1110-
)
1111-
or
1112-
exists(Function f |
1113-
VariableCapture::Flow::heuristicAllowInstanceParameterReturnInSelf(f) and
1114-
p = TSynthCapturedVariablesParameterNode(f)
1115-
)
1116-
}
1117-
11181099
/** An approximated `Content`. */
11191100
class ContentApprox = Unit;
11201101

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

-17
Original file line numberDiff line numberDiff line change
@@ -2107,23 +2107,6 @@ predicate knownSinkModel(Node sink, string model) {
21072107

21082108
class DataFlowSecondLevelScope = Unit;
21092109

2110-
/**
2111-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
2112-
* side-effect, resulting in a summary from `p` to itself.
2113-
*
2114-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
2115-
* by default as a heuristic.
2116-
*/
2117-
predicate allowParameterReturnInSelf(ParameterNodeImpl p) {
2118-
exists(DataFlowCallable c, ParameterPosition pos |
2119-
p.isParameterOf(c, pos) and
2120-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asLibraryCallable(), pos)
2121-
)
2122-
or
2123-
VariableCapture::Flow::heuristicAllowInstanceParameterReturnInSelf(p.(LambdaSelfReferenceNode)
2124-
.getCallable())
2125-
}
2126-
21272110
/** An approximated `Content`. */
21282111
class ContentApprox extends TContentApprox {
21292112
string toString() {

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

-14
Original file line numberDiff line numberDiff line change
@@ -990,20 +990,6 @@ module RustDataFlow implements InputSig<Location> {
990990
*/
991991
predicate isUnreachableInCall(NodeRegion nr, DataFlowCall call) { none() }
992992

993-
/**
994-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
995-
* side-effect, resulting in a summary from `p` to itself.
996-
*
997-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
998-
* by default as a heuristic.
999-
*/
1000-
predicate allowParameterReturnInSelf(ParameterNode p) {
1001-
exists(DataFlowCallable c, ParameterPosition pos |
1002-
p.isParameterOf(c, pos) and
1003-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asLibraryCallable(), pos)
1004-
)
1005-
}
1006-
1007993
/**
1008994
* Holds if the value of `node2` is given by `node1`.
1009995
*

shared/dataflow/codeql/dataflow/DataFlow.qll

-9
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,6 @@ signature module InputSig<LocationSig Location> {
267267

268268
default int accessPathLimit() { result = 5 }
269269

270-
/**
271-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
272-
* side-effect, resulting in a summary from `p` to itself.
273-
*
274-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
275-
* by default as a heuristic.
276-
*/
277-
predicate allowParameterReturnInSelf(ParameterNode p);
278-
279270
/**
280271
* Holds if the value of `node2` is given by `node1`.
281272
*

shared/dataflow/codeql/dataflow/VariableCapture.qll

-15
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ signature module OutputSig<LocationSig Location, InputSig<Location> I> {
245245
/** Holds if there is a read step from `node1` to `node2`. */
246246
predicate readStep(ClosureNode node1, I::CapturedVariable v, ClosureNode node2);
247247

248-
/** Holds if this-to-this summaries are expected for `c`. */
249-
predicate heuristicAllowInstanceParameterReturnInSelf(I::Callable c);
250-
251248
/** Holds if captured variable `v` is cleared at `node`. */
252249
predicate clearsContent(ClosureNode node, I::CapturedVariable v);
253250
}
@@ -579,18 +576,6 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
579576
exists(Callable c | ce.hasBody(c) and captureAccess(v, c))
580577
}
581578

582-
predicate heuristicAllowInstanceParameterReturnInSelf(Callable c) {
583-
// If multiple variables are captured, then we should allow flow from one to
584-
// another, which entails a this-to-this summary.
585-
2 <= strictcount(CapturedVariable v | captureAccess(v, c))
586-
or
587-
// Constructors that capture a variable may assign it to a field, which also
588-
// entails a this-to-this summary. If there are multiple constructors, then
589-
// they might call each other, so if one constructor captures a variable we
590-
// allow this-to-this summaries for all of them.
591-
exists(ClosureExpr ce | ce.hasBody(c) and c.isConstructor() and hasConstructorCapture(ce, _))
592-
}
593-
594579
/** Holds if a constructor, if any, for the closure defined by `ce` captures `v`. */
595580
private predicate hasConstructorCapture(ClosureExpr ce, CapturedVariable v) {
596581
exists(Callable c | ce.hasBody(c) and c.isConstructor() and captureAccess(v, c))

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

+2-21
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
498498
)
499499
}
500500

501-
/**
502-
* Holds if flow from `p` to a return node of kind `kind` is allowed.
503-
*
504-
* We don't expect a parameter to return stored in itself, unless
505-
* explicitly allowed
506-
*/
507-
bindingset[p, kind]
508-
private predicate parameterFlowThroughAllowed(ParamNodeEx p, ReturnKindExt kind) {
509-
exists(ParameterPosition pos | p.isParameterOf(_, pos) |
510-
not kind.(ParamUpdateReturnKind).getPosition() = pos
511-
or
512-
allowParameterReturnInSelfEx(p)
513-
)
514-
}
515-
516501
private module Stage1 implements StageSig {
517502
class Ap = Unit;
518503

@@ -936,8 +921,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
936921
throughFlowNodeCand(p) and
937922
returnFlowCallableNodeCand(c, kind) and
938923
p.getEnclosingCallable() = c and
939-
exists(ap) and
940-
parameterFlowThroughAllowed(p, kind)
924+
exists(ap)
941925
)
942926
}
943927

@@ -2103,7 +2087,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21032087
TSummaryCtxSome(pragma[only_bind_into](p), _, _, pragma[only_bind_into](argAp), _) and
21042088
not outBarrier(ret, state) and
21052089
kind = ret.getKind() and
2106-
parameterFlowThroughAllowed(p, kind) and
21072090
argApa = getApprox(argAp) and
21082091
PrevStage::returnMayFlowThrough(ret, pragma[only_bind_into](argApa), apa, kind)
21092092
)
@@ -2439,7 +2422,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
24392422
) {
24402423
revFlow(pragma[only_bind_into](p), state, TReturnCtxMaybeFlowThrough(pos),
24412424
apSome(returnAp), pragma[only_bind_into](ap)) and
2442-
parameterFlowThroughAllowed(p, pos.getKind()) and
24432425
PrevStage::parameterMayFlowThrough(p, getApprox(ap))
24442426
}
24452427

@@ -2525,8 +2507,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25252507
private predicate parameterFlowsThroughRev(
25262508
ParamNodeEx p, Ap ap, ReturnPosition pos, Ap returnAp
25272509
) {
2528-
revFlow(p, _, TReturnCtxMaybeFlowThrough(pos), apSome(returnAp), ap) and
2529-
parameterFlowThroughAllowed(p, pos.getKind())
2510+
revFlow(p, _, TReturnCtxMaybeFlowThrough(pos), apSome(returnAp), ap)
25302511
}
25312512

25322513
pragma[nomagic]

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

+2-4
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
16001600
* node `n`, in the same callable, using only value-preserving steps.
16011601
*/
16021602
private predicate parameterValueFlowsToPreUpdate(ParamNode p, PostUpdateNode n) {
1603-
parameterValueFlow(p, n.getPreUpdateNode(), TReadStepTypesNone(), _, _)
1603+
parameterValueFlow(p, n.getPreUpdateNode(), TReadStepTypesNone(), _, _) and
1604+
p != n // needed for Golang
16041605
}
16051606

16061607
cached
@@ -1680,9 +1681,6 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
16801681
reverseStepThroughInputOutputAlias(node1, node2, model)
16811682
}
16821683

1683-
cached
1684-
predicate allowParameterReturnInSelfEx(ParamNodeEx p) { allowParameterReturnInSelf(p.asNode()) }
1685-
16861684
cached
16871685
predicate paramMustFlow(ParamNode p, ArgNode arg) { localMustFlowStep+(p, arg) }
16881686

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

-12
Original file line numberDiff line numberDiff line change
@@ -1051,18 +1051,6 @@ module Make<
10511051
)
10521052
}
10531053

1054-
/**
1055-
* Holds if flow is allowed to pass from the parameter at position `pos` of `c`,
1056-
* to a return node, and back out to the parameter.
1057-
*/
1058-
predicate summaryAllowParameterReturnInSelf(SummarizedCallable c, ParameterPosition ppos) {
1059-
exists(SummaryComponentStack inputContents, SummaryComponentStack outputContents |
1060-
summary(c, inputContents, outputContents, _, _) and
1061-
inputContents.bottom() = pragma[only_bind_into](TArgumentSummaryComponent(ppos)) and
1062-
outputContents.bottom() = pragma[only_bind_into](TArgumentSummaryComponent(ppos))
1063-
)
1064-
}
1065-
10661054
signature module TypesInputSig {
10671055
/** Gets the type of content `c`. */
10681056
DataFlowType getContentType(ContentSet c);

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

-19
Original file line numberDiff line numberDiff line change
@@ -1420,25 +1420,6 @@ predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
14201420

14211421
class DataFlowSecondLevelScope = Unit;
14221422

1423-
/**
1424-
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
1425-
* side-effect, resulting in a summary from `p` to itself.
1426-
*
1427-
* One example would be to allow flow like `p.foo = p.bar;`, which is disallowed
1428-
* by default as a heuristic.
1429-
*/
1430-
predicate allowParameterReturnInSelf(ParameterNode p) {
1431-
exists(Callable c |
1432-
c = p.(ParameterNodeImpl).getEnclosingCallable().asSourceCallable() and
1433-
CaptureFlow::heuristicAllowInstanceParameterReturnInSelf(c)
1434-
)
1435-
or
1436-
exists(DataFlowCallable c, ParameterPosition pos |
1437-
p.(ParameterNodeImpl).isParameterOf(c, pos) and
1438-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asSummarizedCallable(), pos)
1439-
)
1440-
}
1441-
14421423
/** An approximated `Content`. */
14431424
class ContentApprox = Unit;
14441425

0 commit comments

Comments
 (0)