mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-14 01:24:12 -08:00
Fix: Add safety check to hwmon read
Some checks failed
golangci-lint / lint (push) Has been cancelled
Some checks failed
golangci-lint / lint (push) Has been cancelled
Avoid panic for accessing slice out of range in hwmon. Fixes: https://github.com/prometheus/node_exporter/issues/3108 Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
ebf3cbfbb3
commit
1b332edfe8
|
@ -18,6 +18,7 @@ package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -107,6 +108,9 @@ func sysReadFile(file string) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if n < 0 {
|
||||||
|
return nil, fmt.Errorf("failed to read file: %q, read returned negative bytes value: %d", file, n)
|
||||||
|
}
|
||||||
|
|
||||||
return b[:n], nil
|
return b[:n], nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue