Skip to content

Commit

Permalink
service: fixed buffer too low error (#1745)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Nov 18, 2024
1 parent 9f29fc8 commit c6ee794
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/collector/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit c6ee794

Please sign in to comment.