Skip to content

Commit cbf722d

Browse files
committed
Ruby: Add SummarizedCallable::getParameter
1 parent 3593806 commit cbf722d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

ruby/ql/lib/codeql/ruby/dataflow/FlowSummary.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import codeql.ruby.AST
44
import codeql.ruby.DataFlow
55
private import internal.FlowSummaryImpl as Impl
66
private import internal.DataFlowDispatch
7+
private import internal.DataFlowImplCommon as DataFlowImplCommon
78
private import internal.DataFlowPrivate
9+
private import internal.FlowSummaryImplSpecific
810

911
// import all instances below
1012
private module Summaries {
@@ -127,6 +129,17 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
127129
*/
128130
pragma[nomagic]
129131
predicate propagatesFlowExt(string input, string output, boolean preservesValue) { none() }
132+
133+
/**
134+
* Gets the synthesized parameter that results from an input specification
135+
* that starts with `Argument[s]` for this library callable.
136+
*/
137+
DataFlow::ParameterNode getParameter(string s) {
138+
exists(ParameterPosition pos |
139+
DataFlowImplCommon::parameterNode(result, TLibraryCallable(this), pos) and
140+
s = getParameterPositionCsv(pos)
141+
)
142+
}
130143
}
131144

132145
/**

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,32 @@ string getComponentSpecificCsv(SummaryComponent sc) { none() }
145145

146146
/** Gets the textual representation of a parameter position in the format used for flow summaries. */
147147
string getParameterPositionCsv(ParameterPosition pos) {
148-
pos.isSelf() and result = "self"
149-
or
150-
pos.isBlock() and result = "block"
151-
or
152148
exists(int i |
153149
pos.isPositional(i) and
154150
result = i.toString()
155151
)
156152
or
153+
exists(int i |
154+
pos.isPositionalLowerBound(i) and
155+
result = i + ".."
156+
)
157+
or
157158
exists(string name |
158159
pos.isKeyword(name) and
159160
result = name + ":"
160161
)
162+
or
163+
pos.isSelf() and
164+
result = "self"
165+
or
166+
pos.isBlock() and
167+
result = "block"
168+
or
169+
pos.isAny() and
170+
result = "any"
171+
or
172+
pos.isAnyNamed() and
173+
result = "any-named"
161174
}
162175

163176
/** Gets the textual representation of an argument position in the format used for flow summaries. */

0 commit comments

Comments
 (0)