From af4c1bd685958558497e88ad57c28288f38185b3 Mon Sep 17 00:00:00 2001 From: Tudor Golubenco Date: Tue, 11 Oct 2016 12:43:01 +0200 Subject: [PATCH] Improve error handling on darwin Errors were ignored in fairly dangerous places, which could result in infinite loops. Potential fix for elastic/beats#2747. --- sigar_darwin.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sigar_darwin.go b/sigar_darwin.go index 82f7a4bff..5dbb046e9 100644 --- a/sigar_darwin.go +++ b/sigar_darwin.go @@ -364,10 +364,16 @@ func kern_procargs(pid int, if exe != nil { exe(string(chop(path))) } + if err != nil { + return fmt.Errorf("Error reading the argv[0]: %v", err) + } // skip trailing \0's for { - c, _ := bbuf.ReadByte() + c, err := bbuf.ReadByte() + if err != nil { + return fmt.Errorf("Error skipping nils: %v", err) + } if c != 0 { bbuf.UnreadByte() break // start of argv[0] @@ -379,6 +385,9 @@ func kern_procargs(pid int, if err == io.EOF { break } + if err != nil { + return fmt.Errorf("Error reading args: %v", err) + } if argv != nil { argv(string(chop(arg))) } @@ -395,6 +404,9 @@ func kern_procargs(pid int, if err == io.EOF || line[0] == 0 { break } + if err != nil { + return fmt.Errorf("Error reading args: %v", err) + } pair := bytes.SplitN(chop(line), delim, 2) env(string(pair[0]), string(pair[1])) }