This is an automated email from the ASF dual-hosted git repository. liuhan pushed a commit to branch fix-npe in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git
commit 83935bbd1bea36e19d3fcc618484dc3ea991e538 Author: mrproliu <[email protected]> AuthorDate: Thu Dec 26 20:35:32 2024 +0800 fix NPE when Buffer.Slice --- pkg/tools/buffer/buffer.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/tools/buffer/buffer.go b/pkg/tools/buffer/buffer.go index 7a74fc8..dd9ce4d 100644 --- a/pkg/tools/buffer/buffer.go +++ b/pkg/tools/buffer/buffer.go @@ -260,36 +260,49 @@ func (r *Buffer) Slice(validated bool, start, end *Position) *Buffer { dataEvents := list.New() detailEvents := list.New() var firstDetailElement *list.Element + var lastBufferDataId = start.DataID() for nextElement := start.element; nextElement != end.element; nextElement = nextElement.Next() { - if nextElement == nil { + if nextElement == nil || nextElement.Value == nil { break } + currentBuffer := nextElement.Value.(SocketDataBuffer) // found first matches detail event if detailEvents.Len() == 0 || firstDetailElement == nil { for e := r.detailEvents.Front(); e != nil; e = e.Next() { - if e.Value.(SocketDataDetail).DataID() >= nextElement.Value.(SocketDataBuffer).DataID() { + if e.Value == nil { + continue + } + if e.Value.(SocketDataDetail).DataID() >= currentBuffer.DataID() { detailEvents.PushBack(e.Value) firstDetailElement = e break } } } - dataEvents.PushBack(nextElement.Value) + dataEvents.PushBack(currentBuffer) + lastBufferDataId = currentBuffer.DataID() } lastBuffer := end.element.Value.(SocketDataBuffer) dataEvents.PushBack(&SocketDataEventLimited{SocketDataBuffer: lastBuffer, Size: end.bufIndex}) // if the first detail element been found, append the details until the last buffer data id + var lastBufferId = lastBufferDataId + if lastBuffer != nil { + lastBufferId = lastBuffer.DataID() + } if firstDetailElement == nil && r.detailEvents != nil { for e := r.detailEvents.Front(); e != nil; e = e.Next() { - if e.Value.(SocketDataDetail).DataID() == lastBuffer.DataID() { + if e.Value != nil && e.Value.(SocketDataDetail).DataID() == lastBufferId { detailEvents.PushBack(e.Value) break } } - } else if firstDetailElement != nil && firstDetailElement.Value.(SocketDataDetail).DataID() != lastBuffer.DataID() { + } else if firstDetailElement != nil && firstDetailElement.Value.(SocketDataDetail).DataID() != lastBufferId { for tmp := firstDetailElement.Next(); tmp != nil; tmp = tmp.Next() { - if tmp.Value.(SocketDataDetail).DataID() > lastBuffer.DataID() { + if tmp.Value == nil { + continue + } + if tmp.Value.(SocketDataDetail).DataID() > lastBufferId { break } detailEvents.PushBack(tmp.Value)
