Skip to content

Commit

Permalink
Improve error handling on darwin
Browse files Browse the repository at this point in the history
Errors were ignored in fairly dangerous places, which could result
in infinite loops. Potential fix for elastic/beats#2747.
  • Loading branch information
Tudor Golubenco committed Oct 11, 2016
1 parent 24abf0d commit af4c1bd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sigar_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)))
}
Expand All @@ -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]))
}
Expand Down

0 comments on commit af4c1bd

Please sign in to comment.