Skip to content

Commit c9ad416

Browse files
committed
Fix: Add safety check to hwmon read
Avoid panic for accessing slice out of range in hwmon. Fixes: #3108 Signed-off-by: Ben Kochie <[email protected]>
1 parent 71d9b6c commit c9ad416

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

collector/hwmon_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package collector
1818

1919
import (
2020
"errors"
21+
"fmt"
2122
"log/slog"
2223
"os"
2324
"path/filepath"
@@ -107,6 +108,9 @@ func sysReadFile(file string) ([]byte, error) {
107108
if err != nil {
108109
return nil, err
109110
}
111+
if n < 0 {
112+
return nil, fmt.Errorf("failed to read file: %q", file)
113+
}
110114

111115
return b[:n], nil
112116
}

0 commit comments

Comments
 (0)