Skip to content

Commit 13d01f1

Browse files
committed
Ruby/Python: add recursion guard
1 parent 14c71a3 commit 13d01f1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Attributes
99
import LocalSources
1010
private import semmle.python.essa.SsaCompute
1111
private import semmle.python.dataflow.new.internal.ImportStar
12+
private import semmle.python.frameworks.data.ModelsAsData
1213
private import FlowSummaryImpl as FlowSummaryImpl
1314
private import semmle.python.frameworks.data.ModelsAsData
1415

@@ -125,6 +126,12 @@ newtype TNode =
125126
f = any(VariableCapture::CapturedVariable v).getACapturingScope() and
126127
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
127128
exists(TFunction(f))
129+
} or
130+
TForbiddenRecursionGuard() {
131+
none() and
132+
// We want to prune irrelevant models before materialising data flow nodes, so types contributed
133+
// directly from CodeQL must expose their pruning info without depending on data flow nodes.
134+
(any(ModelInput::TypeModel tm).isTypeUsed("") implies any())
128135
}
129136

130137
private import semmle.python.internal.CachedStages

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,13 @@ private module Cached {
588588
n in [-1 .. 10] and
589589
splatPos = unique(int i | splatArgumentAt(c, i) and i > 0)
590590
} or
591-
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn)
591+
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
592+
TForbiddenRecursionGuard() {
593+
none() and
594+
// We want to prune irrelevant models before materialising data flow nodes, so types contributed
595+
// directly from CodeQL must expose their pruning info without depending on data flow nodes.
596+
(any(ModelInput::TypeModel tm).isTypeUsed("") implies any())
597+
}
592598

593599
class TSelfParameterNode = TSelfMethodParameterNode or TSelfToplevelParameterNode;
594600

0 commit comments

Comments
 (0)