Skip to content

Commit 39f3b34

Browse files
authored
Merge pull request #1392 from brianryner8/getfsstat-count
Truncate the Getfsstat result to the count of items that were returned
2 parents bd21a78 + 8d22915 commit 39f3b34

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

disk/disk_darwin.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
2020
return ret, err
2121
}
2222
fs := make([]unix.Statfs_t, count)
23-
if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
23+
count, err = unix.Getfsstat(fs, unix.MNT_WAIT)
24+
if err != nil {
2425
return ret, err
2526
}
27+
// On 10.14, and possibly other OS versions, the actual count may
28+
// be less than from the first call. Truncate to the returned count
29+
// to prevent accessing uninitialized entries.
30+
// https://github.com/shirou/gopsutil/issues/1390
31+
fs = fs[:count]
2632
for _, stat := range fs {
2733
opts := []string{"rw"}
2834
if stat.Flags&unix.MNT_RDONLY != 0 {

0 commit comments

Comments
 (0)