Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -676,26 +676,28 @@ private module Cached {
)
}

private predicate fieldName(string name) {
name = any(InstanceVariable v).getName()
or
name = "@" + any(SetterMethodCall c).getTargetName()
or
// The following equation unfortunately leads to a non-monotonic recursion error:
// name = any(AccessPathToken a).getAnArgument("Field")
// Therefore, we use the following instead to extract the field names from the
// external model data. This, unfortunately, does not included any field names used
// in models defined in QL code.
exists(string input, string output |
ModelOutput::relevantSummaryModel(_, _, input, output, _, _)
|
name = [input, output].regexpFind("(?<=(^|\\.)Field\\[)[^\\]]+(?=\\])", _, _).trim()
)
}

cached
newtype TContent =
TKnownElementContent(ConstantValue cv) { trackKnownValue(cv) } or
TUnknownElementContent() or
TFieldContent(string name) {
name = any(InstanceVariable v).getName()
or
name = "@" + any(SetterMethodCall c).getTargetName()
or
// The following equation unfortunately leads to a non-monotonic recursion error:
// name = any(AccessPathToken a).getAnArgument("Field")
// Therefore, we use the following instead to extract the field names from the
// external model data. This, unfortunately, does not included any field names used
// in models defined in QL code.
exists(string input, string output |
ModelOutput::relevantSummaryModel(_, _, input, output, _, _)
|
name = [input, output].regexpFind("(?<=(^|\\.)Field\\[)[^\\]]+(?=\\])", _, _).trim()
)
} or
TFieldContent(string name) { fieldName(name) } or
deprecated TSplatContent(int i, Boolean shifted) { i in [0 .. 10] } or
deprecated THashSplatContent(ConstantValue::ConstantSymbolValue cv) or
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
Expand All @@ -716,12 +718,20 @@ private module Cached {
)
}

cached
int fieldNameBucket(string name) {
exists(int r | name = rank[r](string n | fieldName(n)) and result = r % 30)
}

cached
newtype TContentApprox =
TUnknownElementContentApprox() or
TKnownIntegerElementContentApprox() or
TKnownElementContentApprox(string approx) { approx = approxKnownElementIndex(_) } or
TNonElementContentApprox(Content c) { not c instanceof Content::ElementContent } or
TFieldContentApprox(int bucket) { bucket = fieldNameBucket(_) } or
TNonElementContentApprox(Content c) {
not c instanceof Content::ElementContent and not c instanceof Content::FieldContent
} or
TCapturedVariableContentApprox(VariableCapture::CapturedVariable v)

cached
Expand Down Expand Up @@ -2268,6 +2278,10 @@ class ContentApprox extends TContentApprox {
result = "approximated element " + approx
)
or
exists(int bucket |
this = TFieldContentApprox(bucket) and result = "field bucket " + bucket.toString()
)
or
exists(Content c |
this = TNonElementContentApprox(c) and
result = c.toString()
Expand Down Expand Up @@ -2307,6 +2321,8 @@ ContentApprox getContentApprox(Content c) {
result =
TKnownElementContentApprox(approxKnownElementIndex(c.(Content::KnownElementContent).getIndex()))
or
result = TFieldContentApprox(fieldNameBucket(c.(Content::FieldContent).getName()))
or
result = TNonElementContentApprox(c)
}

Expand Down
Loading