mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-25 14:16:36 +00:00
fix: buffer length panic (#1936)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
(cherry picked from commit eecc6ce574)
This commit is contained in:
committed by
Jan-Otto Kröpke
parent
c300935170
commit
9da6e56fcf
@@ -180,7 +180,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the info with the current buffer size
|
// Get the info with the current buffer size
|
||||||
bufLen := uint32(0)
|
var bufLen uint32
|
||||||
|
|
||||||
if ret := GetCounterInfo(counterHandle, 0, &bufLen, nil); ret != MoreData {
|
if ret := GetCounterInfo(counterHandle, 0, &bufLen, nil); ret != MoreData {
|
||||||
errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))
|
errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))
|
||||||
@@ -188,13 +188,13 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if bufLen == 0 {
|
buf := make([]byte, bufLen)
|
||||||
|
if len(buf) == 0 {
|
||||||
errs = append(errs, errors.New("GetCounterInfo: buffer length is zero"))
|
errs = append(errs, errors.New("GetCounterInfo: buffer length is zero"))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, bufLen)
|
|
||||||
if ret := GetCounterInfo(counterHandle, 0, &bufLen, &buf[0]); ret != ErrorSuccess {
|
if ret := GetCounterInfo(counterHandle, 0, &bufLen, &buf[0]); ret != ErrorSuccess {
|
||||||
errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))
|
errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user