Skip to content

Commit ab37ae6

Browse files
authored
Merge pull request #7036 from hvitved/ruby/truncate-get-value-text
Ruby: Truncate concatenated strings in `getValueText`
2 parents e6145f0 + 8b287a7 commit ab37ae6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class ExprCfgNode extends AstCfgNode {
108108
}
109109

110110
/** Gets the textual (constant) value of this expression, if any. */
111+
cached
111112
string getValueText() { result = this.getSource().getValueText() }
112113
}
113114

@@ -247,7 +248,18 @@ module ExprNodes {
247248
result = (left.toFloat() + right.toFloat()).toString()
248249
or
249250
not (exists(left.toFloat()) and exists(right.toFloat())) and
250-
result = left + right
251+
exists(int l, int r, int limit |
252+
l = left.length() and
253+
r = right.length() and
254+
limit = 10000
255+
|
256+
if l > limit
257+
then result = left.prefix(limit) + "..."
258+
else
259+
if l + r > limit
260+
then result = left + right.prefix(limit - l) + "..."
261+
else result = left + right
262+
)
251263
)
252264
or
253265
op = "-" and

0 commit comments

Comments
 (0)