mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Merge pull request #17880 from hvitved/ruby/symbol-string-key-indifference
Ruby: Do not distinguish between symbols and strings in hash keys
This commit is contained in:
@@ -829,7 +829,28 @@ class ContentSet extends TContentSet {
|
||||
this.isAny() and
|
||||
exists(result)
|
||||
or
|
||||
result = this.getAnElementReadContent()
|
||||
exists(Content elementContent | elementContent = this.getAnElementReadContent() |
|
||||
result = elementContent
|
||||
or
|
||||
// Do not distinguish symbol keys from string keys. This allows us to
|
||||
// give more precise summaries for something like `with_indifferent_access`,
|
||||
// and the amount of false-positive flow arising from this should be very
|
||||
// limited.
|
||||
elementContent =
|
||||
any(Content::KnownElementContent known, ConstantValue cv |
|
||||
cv = known.getIndex() and
|
||||
result.(Content::KnownElementContent).getIndex() =
|
||||
any(ConstantValue cv2 |
|
||||
cv2.(ConstantValue::ConstantSymbolValue).getStringlikeValue() =
|
||||
cv.(ConstantValue::ConstantStringValue).getStringlikeValue()
|
||||
or
|
||||
cv2.(ConstantValue::ConstantStringValue).getStringlikeValue() =
|
||||
cv.(ConstantValue::ConstantSymbolValue).getStringlikeValue()
|
||||
)
|
||||
|
|
||||
known
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,16 +121,6 @@ module ActiveSupport {
|
||||
* Extensions to the `Hash` class.
|
||||
*/
|
||||
module Hash {
|
||||
private class WithIndifferentAccessSummary extends SimpleSummarizedCallable {
|
||||
WithIndifferentAccessSummary() { this = "with_indifferent_access" }
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].Element[any]" and
|
||||
output = "ReturnValue.Element[any]" and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flow summary for `reverse_merge`, and its alias `with_defaults`.
|
||||
*/
|
||||
@@ -167,8 +157,9 @@ module ActiveSupport {
|
||||
}
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].Element[any]" and
|
||||
output = "ReturnValue.Element[?]" and
|
||||
// keys are considered equal modulo string/symbol in our implementation
|
||||
input = "Argument[self].WithElement[any]" and
|
||||
output = "ReturnValue" and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user