Skip to content

Commit 3afa942

Browse files
committed
Ruby: Add TAnyKeywordArgumentPosition and TAnyKeywordParameterPosition
1 parent 5d6fbce commit 3afa942

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ module API {
790790
result = Label::blockParameter()
791791
// NOTE: `self` should NOT be included, as described in the QLDoc for `isAny()`
792792
)
793+
or
794+
pos.isAnyNamed() and
795+
result = Label::keywordParameter(_)
793796
// TODO: needs handling of `self` ArgumentPosition
794797
// or
795798
// pos.isSelf() and
@@ -820,6 +823,9 @@ module API {
820823
result = Label::blockParameter()
821824
// NOTE: `self` should NOT be included, as described in the QLDoc for `isAny()`
822825
)
826+
or
827+
pos.isAnyNamed() and
828+
result = Label::keywordParameter(_)
823829
// TODO: needs handling of `self` ParameterPosition
824830
// or
825831
// pos.isSelf() and

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ private module Cached {
260260
or
261261
FlowSummaryImplSpecific::ParsePositions::isParsedKeywordParameterPosition(_, name)
262262
} or
263-
TAnyArgumentPosition()
263+
TAnyArgumentPosition() or
264+
TAnyKeywordArgumentPosition()
264265

265266
cached
266267
newtype TParameterPosition =
@@ -279,7 +280,8 @@ private module Cached {
279280
or
280281
FlowSummaryImplSpecific::ParsePositions::isParsedKeywordArgumentPosition(_, name)
281282
} or
282-
TAnyParameterPosition()
283+
TAnyParameterPosition() or
284+
TAnyKeywordParameterPosition()
283285
}
284286

285287
import Cached
@@ -483,6 +485,9 @@ class ParameterPosition extends TParameterPosition {
483485
*/
484486
predicate isAny() { this = TAnyParameterPosition() }
485487

488+
/** Holds if this position represents any positional parameter. */
489+
predicate isAnyNamed() { this = TAnyKeywordParameterPosition() }
490+
486491
/** Gets a textual representation of this position. */
487492
string toString() {
488493
this.isSelf() and result = "self"
@@ -496,6 +501,8 @@ class ParameterPosition extends TParameterPosition {
496501
exists(string name | this.isKeyword(name) and result = "keyword " + name)
497502
or
498503
this.isAny() and result = "any"
504+
or
505+
this.isAnyNamed() and result = "any-named"
499506
}
500507
}
501508

@@ -519,6 +526,9 @@ class ArgumentPosition extends TArgumentPosition {
519526
*/
520527
predicate isAny() { this = TAnyArgumentPosition() }
521528

529+
/** Holds if this position represents any positional parameter. */
530+
predicate isAnyNamed() { this = TAnyKeywordArgumentPosition() }
531+
522532
/** Gets a textual representation of this position. */
523533
string toString() {
524534
this.isSelf() and result = "self"
@@ -530,6 +540,8 @@ class ArgumentPosition extends TArgumentPosition {
530540
exists(string name | this.isKeyword(name) and result = "keyword " + name)
531541
or
532542
this.isAny() and result = "any"
543+
or
544+
this.isAnyNamed() and result = "any-named"
533545
}
534546
}
535547

@@ -551,4 +563,8 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
551563
ppos.isAny() and not apos.isSelf()
552564
or
553565
apos.isAny() and not ppos.isSelf()
566+
or
567+
ppos.isAnyNamed() and apos.isKeyword(_)
568+
or
569+
apos.isAnyNamed() and ppos.isKeyword(_)
554570
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ ArgumentPosition parseParamBody(string s) {
262262
result.isAny()
263263
or
264264
s = "any-named" and
265-
result.isKeyword(_)
265+
result.isAnyNamed()
266266
}
267267

268268
/** Gets the parameter position obtained by parsing `X` in `Argument[X]`. */
@@ -292,5 +292,5 @@ ParameterPosition parseArgBody(string s) {
292292
result.isAny()
293293
or
294294
s = "any-named" and
295-
result.isKeyword(_)
295+
result.isAnyNamed()
296296
}

0 commit comments

Comments
 (0)