Skip to content

Commit

Permalink
MINOR: kern_procargs more robut on darwin
Browse files Browse the repository at this point in the history
Under some circonstance the code can fail, the root cause is not clear
at the moment, but we should still make the code more robust when
retrieving information for a specific process.

The problem is the `bytes.SplitN` can return an array of one element
making the process panic when we access the other element.

This commit make the code a bit more robust and check to make sure we
successfully retrieved 2 elements instead of one and return an error
if it failed.

Reference: elastic/beats#5337
  • Loading branch information
ph committed Oct 10, 2017
1 parent 5a9ad8e commit 411c3b2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sigar_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ func kern_procargs(pid int,
return fmt.Errorf("Error reading args: %v", err)
}
pair := bytes.SplitN(chop(line), delim, 2)
env(string(pair[0]), string(pair[1]))

if len(pair) == 2 {
env(string(pair[0]), string(pair[1]))
} else {
return fmt.Errorf("Error reading process information for PID: %d", pid)
}
}

return nil
Expand Down

0 comments on commit 411c3b2

Please sign in to comment.