mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
fix: buffer length panic (#1936)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -177,7 +177,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)))
|
||||||
@@ -185,23 +185,29 @@ 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)))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ci := (*CounterInfo)(unsafe.Pointer(&buf[0]))
|
counterInfo := (*CounterInfo)(unsafe.Pointer(&buf[0]))
|
||||||
counter.Type = ci.DwType
|
if counterInfo == nil {
|
||||||
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
|
errs = append(errs, errors.New("GetCounterInfo: counter info is nil"))
|
||||||
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
counter.Type = counterInfo.DwType
|
||||||
|
counter.Desc = windows.UTF16PtrToString(counterInfo.SzExplainText)
|
||||||
|
counter.Desc = windows.UTF16PtrToString(counterInfo.SzExplainText)
|
||||||
|
|
||||||
if val, ok := SupportedCounterTypes[counter.Type]; ok {
|
if val, ok := SupportedCounterTypes[counter.Type]; ok {
|
||||||
counter.MetricType = val
|
counter.MetricType = val
|
||||||
|
|||||||
Reference in New Issue
Block a user