mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-03-05 21:00:12 -08:00
Fix: Add safety check to hwmon read
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
71d9b6c061
commit
3ed088616a
|
@ -107,6 +107,9 @@ func sysReadFile(file string) ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n < 0 {
|
||||
return nil, fmt.Errorf("failed to read file: %w", file)
|
||||
}
|
||||
|
||||
return b[:n], nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue