proc: bugfix: crash when a negative depth is used for Stacktrace

This commit is contained in:
aarzilli 2016-02-02 12:26:29 +01:00
parent 94a265f098
commit 0945170772
2 changed files with 17 additions and 0 deletions

@ -2,6 +2,7 @@ package proc
import (
"encoding/binary"
"errors"
"fmt"
)
@ -164,6 +165,9 @@ func (dbp *Process) frameInfo(pc, sp uint64, top bool) (Stackframe, error) {
}
func (dbp *Process) stacktrace(pc, sp uint64, depth int) ([]Stackframe, error) {
if depth < 0 {
return nil, errors.New("negative maximum stack depth")
}
frames := make([]Stackframe, 0, depth+1)
it := newStackIterator(dbp, pc, sp)
for it.Next() {

@ -798,3 +798,16 @@ func TestIssue355(t *testing.T) {
assertError(err, t, "FindLocation()")
})
}
func TestNegativeStackDepthBug(t *testing.T) {
// After the target process has terminated should return an error but not crash
withTestClient("continuetestprog", t, func(c service.Client) {
_, err := c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.sayhi", Line: -1})
assertNoError(err, t, "CreateBreakpoint()")
ch := c.Continue()
state := <-ch
assertNoError(state.Err, t, "Continue()")
_, err = c.Stacktrace(-1, -2, true)
assertError(err, t, "Stacktrace()")
})
}