From 78069e44c7a9a79c8097d9b726bf408bb4fd6f5f Mon Sep 17 00:00:00 2001 From: Artem Glazychev Date: Tue, 12 Dec 2023 04:49:45 +0700 Subject: [PATCH] Add check for stats vector length (#172) Signed-off-by: Artem Glazychev --- adapter/statsclient/statseg_v2.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adapter/statsclient/statseg_v2.go b/adapter/statsclient/statseg_v2.go index f8081124..2ed578bd 100644 --- a/adapter/statsclient/statseg_v2.go +++ b/adapter/statsclient/statseg_v2.go @@ -315,6 +315,9 @@ func (ss *statSegmentV2) UpdateEntryData(segment dirSegment, stat *adapter.Stat) } vecLen := *(*uint32)(vectorLen(dirVector)) data := (*stat).(adapter.CombinedCounterStat) + if uint32(len(data)) != vecLen { + return ErrStatDataLenIncorrect + } for i := uint32(0); i < vecLen; i++ { counterVectorOffset := statSegPointer(dirVector, uintptr(i+1)*unsafe.Sizeof(uint64(0))) counterVector := ss.adjust(vectorLen(counterVectorOffset)) @@ -339,6 +342,9 @@ func (ss *statSegmentV2) UpdateEntryData(segment dirSegment, stat *adapter.Stat) } vecLen := *(*uint32)(vectorLen(dirVector)) data := (*stat).(adapter.NameStat) + if uint32(len(data)) != vecLen { + return ErrStatDataLenIncorrect + } for i := uint32(0); i < vecLen; i++ { nameVectorOffset := statSegPointer(dirVector, uintptr(i+1)*unsafe.Sizeof(uint64(0))) if uintptr(nameVectorOffset) == 0 {