From 9da6e56fcf91ee84a4ab61b91c30b4aed8e371af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Fri, 14 Mar 2025 10:57:47 +0100 Subject: [PATCH] fix: buffer length panic (#1936) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke (cherry picked from commit eecc6ce574a398cb93d730b5eb2ee0819946a469) --- internal/pdh/collector.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/pdh/collector.go b/internal/pdh/collector.go index 43b9d33e..9bd03133 100644 --- a/internal/pdh/collector.go +++ b/internal/pdh/collector.go @@ -180,7 +180,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances } // Get the info with the current buffer size - bufLen := uint32(0) + var bufLen uint32 if ret := GetCounterInfo(counterHandle, 0, &bufLen, nil); ret != MoreData { errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret))) @@ -188,13 +188,13 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances continue } - if bufLen == 0 { + buf := make([]byte, bufLen) + if len(buf) == 0 { errs = append(errs, errors.New("GetCounterInfo: buffer length is zero")) continue } - buf := make([]byte, bufLen) if ret := GetCounterInfo(counterHandle, 0, &bufLen, &buf[0]); ret != ErrorSuccess { errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))