Skip to content

Commit

Permalink
Fix out-of-bound index access
Browse files Browse the repository at this point in the history
  • Loading branch information
amomchilov committed Jan 4, 2024
1 parent 821a8cb commit a0a8b3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/debug/variable_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class VariableInspector
def indexed_members_of(obj, start:, count:)
return [] if start > (obj.length - 1)

(start...(start + count)).map do |i|
capped_count = [count, obj.length - start].min

(start...(start + capped_count)).map do |i|
Variable.new(name: i.to_s, value: obj[i])
end
end
Expand Down
26 changes: 9 additions & 17 deletions test/protocol/hover_raw_dap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,6 @@ def test_hover_works_correctly
variablesReference: 30,
namedVariables: /\d+/
},
{
# This is an extra entry caused by an out-of-bounds index access in server_dap.rb
name: "9",
value: nil,
type: NilClass,
variablesReference: 31,
namedVariables: /\d+/
}
]
}
},
Expand All @@ -649,7 +641,7 @@ def test_hover_works_correctly
message: "Success",
body: {
type: "Integer",
variablesReference: 32,
variablesReference: 31,
namedVariables: /\d+/,
result: "3"
}
Expand All @@ -658,7 +650,7 @@ def test_hover_works_correctly
seq: 23,
command: "variables",
arguments: {
variablesReference: 32
variablesReference: 31
},
type: "request"
},
Expand All @@ -675,7 +667,7 @@ def test_hover_works_correctly
name: "#class",
value: "Integer",
type: "Class",
variablesReference: 33,
variablesReference: 32,
namedVariables: /\d+/
}
]
Expand All @@ -700,7 +692,7 @@ def test_hover_works_correctly
message: "Success",
body: {
type: "Integer",
variablesReference: 34,
variablesReference: 33,
namedVariables: /\d+/,
result: "2"
}
Expand All @@ -709,7 +701,7 @@ def test_hover_works_correctly
seq: 25,
command: "variables",
arguments: {
variablesReference: 34
variablesReference: 33
},
type: "request"
},
Expand All @@ -726,7 +718,7 @@ def test_hover_works_correctly
name: "#class",
value: "Integer",
type: "Class",
variablesReference: 35,
variablesReference: 34,
namedVariables: /\d+/
}
]
Expand All @@ -751,7 +743,7 @@ def test_hover_works_correctly
message: "Success",
body: {
type: "Integer",
variablesReference: 36,
variablesReference: 35,
namedVariables: /\d+/,
result: "1"
}
Expand All @@ -760,7 +752,7 @@ def test_hover_works_correctly
seq: 27,
command: "variables",
arguments: {
variablesReference: 36
variablesReference: 35
},
type: "request"
},
Expand All @@ -777,7 +769,7 @@ def test_hover_works_correctly
name: "#class",
value: "Integer",
type: "Class",
variablesReference: 37,
variablesReference: 36,
namedVariables: /\d+/
}
]
Expand Down

0 comments on commit a0a8b3b

Please sign in to comment.