From c6ee7945984b5ef013060d6bda605974d909859e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Mon, 18 Nov 2024 17:39:42 +0100 Subject: [PATCH] service: fixed buffer too low error (#1745) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/collector/service/service.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/collector/service/service.go b/internal/collector/service/service.go index 7b7ac1e5c..8edf99186 100644 --- a/internal/collector/service/service.go +++ b/internal/collector/service/service.go @@ -440,6 +440,8 @@ func (c *Collector) getServiceConfig(service *mgr.Service) (mgr.Config, error) { buf, ok := c.serviceConfigPoolBytes.Get().(*[]byte) if !ok || len(*buf) == 0 { *buf = make([]byte, bytesNeeded) + } else { + bytesNeeded = uint32(cap(*buf)) } for { @@ -450,12 +452,12 @@ func (c *Collector) getServiceConfig(service *mgr.Service) (mgr.Config, error) { break } - if !errors.Is(err, windows.ERROR_INSUFFICIENT_BUFFER) { + if !errors.Is(err, windows.ERROR_INSUFFICIENT_BUFFER) && !errors.Is(err, windows.ERROR_MORE_DATA) { return mgr.Config{}, err } if bytesNeeded <= uint32(len(*buf)) { - return mgr.Config{}, err + return mgr.Config{}, fmt.Errorf("win32 reports buffer too small (%d), but buffer is large enough (%d): %w", uint32(cap(*buf)), bytesNeeded, err) } *buf = make([]byte, bytesNeeded)