aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid O'Rourke <david.orourke@gmail.com>2020-05-30 18:10:33 +0100
committerJohannes 'fish' Ziemke <github@freigeist.org>2020-06-03 11:33:10 +0200
commit4c06e33c2341cdce81cf1765a3b563d5d9a2042e (patch)
tree0fdef0e09cf35c1b0e3b9f8ce97b9b79713265ad
parent2c433cdac30181ac078c8558dc43c5da42638c07 (diff)
downloadprometheus_node_collector-4c06e33c2341cdce81cf1765a3b563d5d9a2042e.tar.bz2
prometheus_node_collector-4c06e33c2341cdce81cf1765a3b563d5d9a2042e.tar.xz
prometheus_node_collector-4c06e33c2341cdce81cf1765a3b563d5d9a2042e.zip
filesystem_freebsd: Fix label values
We must know the length of the various filesystem C strings before turning them from a byte array into a Go string, otherwise our Go strings could contain null bytes, corrupting the label values. Signed-off-by: David O'Rourke <david.orourke@gmail.com>
-rw-r--r--collector/filesystem_freebsd.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go
index f37029e..8bc8314 100644
--- a/collector/filesystem_freebsd.go
+++ b/collector/filesystem_freebsd.go
@@ -16,6 +16,8 @@
16package collector 16package collector
17 17
18import ( 18import (
19 "bytes"
20
19 "github.com/go-kit/kit/log/level" 21 "github.com/go-kit/kit/log/level"
20 "golang.org/x/sys/unix" 22 "golang.org/x/sys/unix"
21) 23)
@@ -40,14 +42,19 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
40 } 42 }
41 stats := []filesystemStats{} 43 stats := []filesystemStats{}
42 for _, fs := range buf { 44 for _, fs := range buf {
43 mountpoint := string(fs.Mntonname[:]) 45 // We need to work out the lengths of the actual strings here,
46 // otherwuse we will end up with null bytes in our label values.
47 mountpoint_len := bytes.Index(fs.Mntonname[:], []byte{0})
48 mountpoint := string(fs.Mntonname[:mountpoint_len])
44 if c.ignoredMountPointsPattern.MatchString(mountpoint) { 49 if c.ignoredMountPointsPattern.MatchString(mountpoint) {
45 level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) 50 level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint)
46 continue 51 continue
47 } 52 }
48 53
49 device := string(fs.Mntfromname[:]) 54 device_len := bytes.Index(fs.Mntfromname[:], []byte{0})
50 fstype := string(fs.Fstypename[:]) 55 fstype_len := bytes.Index(fs.Fstypename[:], []byte{0})
56 device := string(fs.Mntfromname[:device_len])
57 fstype := string(fs.Fstypename[:fstype_len])
51 if c.ignoredFSTypesPattern.MatchString(fstype) { 58 if c.ignoredFSTypesPattern.MatchString(fstype) {
52 level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) 59 level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype)
53 continue 60 continue