Skip to content

Commit 993dfee

Browse files
committed
log/mem: index out of bounds
1 parent ffa6fe8 commit 993dfee

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

intra/log/memconsole.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,18 @@ rollover:
258258
b := mc.bufs[mc.active]
259259

260260
for i < yank && mc.slotIdx < memNumSlots {
261-
slotSize := memSlotSize - 1 // 1 char for '\n'
262261
// the slot at header + slotIdx * slotSize
263-
begin := memHdrSize + mc.slotIdx*slotSize
264-
end := memHdrSize + (mc.slotIdx+1)*slotSize
262+
begin := memHdrSize + mc.slotIdx*memSlotSize
263+
end := memHdrSize + (mc.slotIdx+1)*memSlotSize
265264
slot := b.data[begin:end]
266265

267-
raw := all[i:min(yank, i+slotSize)]
266+
raw := all[i:min(yank, i+memSlotSize-1)]
268267
n := 0
269268
if !bytes.HasPrefix(raw, lpfx) {
270269
n = copy(slot, lpfx)
271270
}
272271
// the last byte is reserved for newline
273-
m := copy(slot[n:slotSize], raw)
272+
m := copy(slot[n:memSlotSize-1], raw)
274273
slot[n+m] = '\n'
275274
// zero-fill the tail so the reader sees no stale data
276275
clear(slot[n+m+1:])

0 commit comments

Comments
 (0)