pull/3687/merge
Ricard Bejarano 3 days ago committed by GitHub
commit 0cd02b2a74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 6
      collector/filesystem_linux.go
  3. 30
      collector/filesystem_linux_test.go

@ -3,7 +3,7 @@
* [CHANGE]
* [FEATURE]
* [ENHANCEMENT]
* [BUGFIX]
* [BUGFIX] filesystem: Prevent panic on mount points with non-UTF-8 names #3
## 1.11.1 / 2026-04-07

@ -211,9 +211,9 @@ func parseFilesystemLabels(mountInfo []*procfs.MountInfo) ([]filesystemLabels, e
mount.MountPoint = strings.ReplaceAll(mount.MountPoint, "\\011", "\t")
filesystems = append(filesystems, filesystemLabels{
device: mount.Source,
mountPoint: rootfsStripPrefix(mount.MountPoint),
fsType: mount.FSType,
device: strings.ToValidUTF8(mount.Source, "<EFBFBD>"),
mountPoint: strings.ToValidUTF8(rootfsStripPrefix(mount.MountPoint), "<EFBFBD>"),
fsType: strings.ToValidUTF8(mount.FSType, "<EFBFBD>"),
mountOptions: mountOptionsString(mount.Options),
superOptions: mountOptionsString(mount.SuperOptions),
major: strconv.Itoa(major),

@ -21,6 +21,7 @@ import (
"sort"
"strings"
"testing"
"unicode/utf8"
"github.com/alecthomas/kingpin/v2"
@ -51,6 +52,35 @@ func Test_parseFilesystemLabelsError(t *testing.T) {
}
}
func Test_parseFilesystemLabelsSanitizesInvalidUTF8(t *testing.T) {
in := []*procfs.MountInfo{
{
MajorMinorVer: "0:0",
Source: "/dev/sd\xe9",
MountPoint: "/mnt/cass\xe9",
FSType: "ext\xe9",
},
}
got, err := parseFilesystemLabels(in)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(got) != 1 {
t.Fatalf("expected 1 filesystem, got %d", len(got))
}
for name, value := range map[string]string{
"device": got[0].device,
"mountPoint": got[0].mountPoint,
"fsType": got[0].fsType,
} {
if !utf8.ValidString(value) {
t.Errorf("expected %s to be valid UTF-8, got %q", name, value)
}
}
}
func Test_isFilesystemReadOnly(t *testing.T) {
tests := map[string]struct {
labels filesystemLabels

Loading…
Cancel
Save