Skip to content

Commit

Permalink
Merge pull request #1392 from brianryner8/getfsstat-count
Browse files Browse the repository at this point in the history
Truncate the Getfsstat result to the count of items that were returned
  • Loading branch information
shirou authored Dec 18, 2022
2 parents bd21a78 + 8d22915 commit 39f3b34
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion disk/disk_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
return ret, err
}
fs := make([]unix.Statfs_t, count)
if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
count, err = unix.Getfsstat(fs, unix.MNT_WAIT)
if err != nil {
return ret, err
}
// On 10.14, and possibly other OS versions, the actual count may
// be less than from the first call. Truncate to the returned count
// to prevent accessing uninitialized entries.
// https://github.com/shirou/gopsutil/issues/1390
fs = fs[:count]
for _, stat := range fs {
opts := []string{"rw"}
if stat.Flags&unix.MNT_RDONLY != 0 {
Expand Down

0 comments on commit 39f3b34

Please sign in to comment.