Skip to content

Commit

Permalink
proc: bugfix: crash when a negative depth is used for Stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Feb 2, 2016
1 parent 94a265f commit 0945170
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions proc/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proc

import (
"encoding/binary"
"errors"
"fmt"
)

Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions service/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
})
}

0 comments on commit 0945170

Please sign in to comment.