process: fix bug in CmdlineSlice where cmdline is empty

Sometimes (at least on linux) cmdline is empty, this was causing
a panic.
This commit is contained in:
Chris Gilling 2016-02-27 18:29:24 -08:00
parent b8c40ac83c
commit d098bf135f
2 changed files with 6 additions and 0 deletions

View File

@ -77,6 +77,9 @@ func (p *Process) CmdlineSlice() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(buf) == 0 {
return nil, nil
}
if buf[len(buf)-1] == 0 { if buf[len(buf)-1] == 0 {
buf = buf[:len(buf)-1] buf = buf[:len(buf)-1]
} }

View File

@ -421,6 +421,9 @@ func (p *Process) fillSliceFromCmdline() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(cmdline) == 0 {
return nil, nil
}
if cmdline[len(cmdline)-1] == 0 { if cmdline[len(cmdline)-1] == 0 {
cmdline = cmdline[:len(cmdline)-1] cmdline = cmdline[:len(cmdline)-1]
} }