From 83b81769df037e1f2910f85e25aa7f8fe3e71ddc Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Larsen Date: Sun, 30 Apr 2017 17:36:55 +0200 Subject: [PATCH] Fix segfault in model.Tree(procs) Fixes crash in model.Tree(procs) which occurs when the list of procs passed, isn't in the expected order. E.g. if the first element doesn't have `PPID == 0`, it would crash writing to the uninitialized `parent.Children`. --- model/proc.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/model/proc.go b/model/proc.go index d73001bdb..1d1c1168b 100644 --- a/model/proc.go +++ b/model/proc.go @@ -44,16 +44,17 @@ func (p *Proc) Failing() bool { // Tree creates a process tree from a flat process list. func Tree(procs []*Proc) []*Proc { var ( - nodes []*Proc - parent *Proc + nodes []*Proc + parent *Proc + children []*Proc ) for _, proc := range procs { if proc.PPID == 0 { nodes = append(nodes, proc) parent = proc - continue + parent.Children = children } else { - parent.Children = append(parent.Children, proc) + children = append(children, proc) } } return nodes