Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix out-of-bound index access
  • Loading branch information
amomchilov authored and st0012 committed Dec 18, 2024
commit ccb86691c0d472d018e3e203d67b9ca8db64e6ba
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