Skip to content

Commit 605fe54

Browse files
hvitvedjoefarebrother
authored andcommitted
Ruby: Remove two Cartesian products
1 parent 5f08371 commit 605fe54

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ private module Cached {
725725
newtype TOptionalContentSet =
726726
TSingletonContent(Content c) or
727727
TAnyElementContent() or
728+
TAnyContent() or
728729
TKnownOrUnknownElementContent(Content::KnownElementContent c) or
729730
TElementLowerBoundContent(int lower, boolean includeUnknown) {
730731
FlowSummaryImpl::ParsePositions::isParsedElementLowerBoundPosition(_, includeUnknown, lower)
@@ -736,7 +737,7 @@ private module Cached {
736737

737738
cached
738739
class TContentSet =
739-
TSingletonContent or TAnyElementContent or TKnownOrUnknownElementContent or
740+
TSingletonContent or TAnyElementContent or TAnyContent or TKnownOrUnknownElementContent or
740741
TElementLowerBoundContent or TElementContentOfTypeContent;
741742

742743
private predicate trackKnownValue(ConstantValue cv) {

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ class ContentSet extends TContentSet {
689689
/** Holds if this content set represents all `ElementContent`s. */
690690
predicate isAnyElement() { this = TAnyElementContent() }
691691

692+
/** Holds if this content set represents all contents. */
693+
predicate isAny() { this = TAnyContent() }
694+
692695
/**
693696
* Holds if this content set represents a specific known element index, or an
694697
* unknown element index.
@@ -737,6 +740,9 @@ class ContentSet extends TContentSet {
737740
this.isAnyElement() and
738741
result = "any element"
739742
or
743+
this.isAny() and
744+
result = "any"
745+
or
740746
exists(Content::KnownElementContent c |
741747
this.isKnownOrUnknownElement(c) and
742748
result = c + " or unknown"
@@ -790,13 +796,8 @@ class ContentSet extends TContentSet {
790796
result = TUnknownElementContent()
791797
}
792798

793-
/** Gets a content that may be read from when reading from this set. */
794-
Content getAReadContent() {
795-
this.isSingleton(result)
796-
or
797-
this.isAnyElement() and
798-
result instanceof Content::ElementContent
799-
or
799+
pragma[nomagic]
800+
private Content getAnElementReadContent() {
800801
exists(Content::KnownElementContent c | this.isKnownOrUnknownElement(c) |
801802
result = c or
802803
result = TSplatContent(c.getIndex().getInt(), _) or
@@ -832,6 +833,19 @@ class ContentSet extends TContentSet {
832833
result = TUnknownElementContent()
833834
)
834835
}
836+
837+
/** Gets a content that may be read from when reading from this set. */
838+
Content getAReadContent() {
839+
this.isSingleton(result)
840+
or
841+
this.isAnyElement() and
842+
result instanceof Content::ElementContent
843+
or
844+
this.isAny() and
845+
exists(result)
846+
or
847+
result = this.getAnElementReadContent()
848+
}
835849
}
836850

837851
/**

ruby/ql/lib/codeql/ruby/security/CleartextLoggingQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private module Config implements DataFlow::ConfigSig {
4646
}
4747

4848
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet cs) {
49-
exists(cs) and
49+
cs.isAny() and
5050
isSink(node)
5151
}
5252
}

ruby/ql/lib/codeql/ruby/security/CleartextStorageQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private module Config implements DataFlow::ConfigSig {
4545
}
4646

4747
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet cs) {
48-
exists(cs) and
48+
cs.isAny() and
4949
isSink(node)
5050
}
5151
}

0 commit comments

Comments
 (0)