From da43049324a8b14812c2691617978d7b3b7bc1e2 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Fri, 3 Jun 2016 11:12:08 +0100 Subject: [PATCH] Fix potential panic in linux disk IO counters Old kernels have a bug in diskstats where lines can have less than 14 fields. This applies to the kernel present in RHEL 5.2 and earlier. It's a bit of a niche but probably best to patch to be safe from future bugs too. RHEL bug case: https://bugzilla.redhat.com/show_bug.cgi?id=583285 Encountered in Telegraf: https://github.com/influxdata/telegraf/issues/1322 --- disk/disk_linux.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index f581ef7..7bdf8c9 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -283,6 +283,10 @@ func IOCounters() (map[string]IOCountersStat, error) { for _, line := range lines { fields := strings.Fields(line) + if len(fields) < 14 { + // malformed line in /proc/diskstats, avoid panic by ignoring. + continue + } name := fields[2] reads, err := strconv.ParseUint((fields[3]), 10, 64) if err != nil { -- GitLab