Skip to content

Commit

Permalink
Fix: Add safety check to hwmon read
Browse files Browse the repository at this point in the history
Avoid panic for accessing slice out of range in hwmon.

Fixes: #3108

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ committed Sep 25, 2024
1 parent 71d9b6c commit 3ed0886
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions collector/hwmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 111 in collector/hwmon_linux.go

View workflow job for this annotation

GitHub Actions / lint

undefined: fmt) (typecheck)

Check failure on line 111 in collector/hwmon_linux.go

View workflow job for this annotation

GitHub Actions / lint

undefined: fmt (typecheck)

Check failure on line 111 in collector/hwmon_linux.go

View workflow job for this annotation

GitHub Actions / lint

undefined: fmt) (typecheck)

Check failure on line 111 in collector/hwmon_linux.go

View workflow job for this annotation

GitHub Actions / lint

undefined: fmt (typecheck)
}

return b[:n], nil
}
Expand Down

0 comments on commit 3ed0886

Please sign in to comment.