Skip to content

Commit bb9348d

Browse files
committed
Ruby: reject ArrayElement[-n] instead of interpreting it as ArrayElement[?]
1 parent a11c6f0 commit bb9348d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ module SummaryComponent {
3232
/** Gets a summary component that represents an element in an array at an unknown index. */
3333
SummaryComponent arrayElementUnknown() { result = SC::content(TUnknownArrayElementContent()) }
3434

35-
/** Gets a summary component that represents an element in an array at a known index. */
35+
/**
36+
* Gets a summary component that represents an element in an array at a known index.
37+
*
38+
* Has no result for negative indices. Wrap-around interpretation of negative indices should be
39+
* handled by the caller, if modeling a function that has such behavior.
40+
*/
3641
bindingset[i]
3742
SummaryComponent arrayElementKnown(int i) {
3843
result = SC::content(TKnownArrayElementContent(i))
3944
or
4045
// `i` may be out of range
46+
i >= 0 and
4147
not exists(TKnownArrayElementContent(i)) and
4248
result = arrayElementUnknown()
4349
}

0 commit comments

Comments
 (0)