proc/variables: crash while reading unintialized variable

Fixes #384
This commit is contained in:
aarzilli 2016-01-30 22:21:07 +01:00 committed by Derek Parker
parent ae6a5f503c
commit 06bba9b7a9
3 changed files with 35 additions and 0 deletions

17
_fixtures/issue384.go Normal file

@ -0,0 +1,17 @@
package main
import (
"fmt"
"reflect"
)
func main() {
type S struct {
F string `species:"gopher" color:"blue"`
}
s := S{}
st := reflect.TypeOf(s)
field := st.Field(0)
fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))
}

@ -1462,3 +1462,16 @@ func TestStepIntoFunction(t *testing.T) {
} }
}) })
} }
func TestIssue384(t *testing.T) {
// Crash related to reading uninitialized memory, introduced by the memory prefetching optimization
withTestProcess("issue384", t, func(p *Process, fixture protest.Fixture) {
start, _, err := p.goSymTable.LineToPC(fixture.Source, 13)
assertNoError(err, t, "LineToPC()")
_, err = p.SetBreakpoint(start)
assertNoError(err, t, "SetBreakpoint()")
assertNoError(p.Continue(), t, "Continue()")
_, err = evalVariable(p, "st")
assertNoError(err, t, "EvalVariable()")
})
}

@ -3,6 +3,7 @@ package proc
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"go/constant" "go/constant"
"go/parser" "go/parser"
@ -927,6 +928,10 @@ func (v *Variable) loadArrayValues(recurseLevel int) {
if v.Unreadable != nil { if v.Unreadable != nil {
return return
} }
if v.Len < 0 {
v.Unreadable = errors.New("Negative array length")
return
}
count := v.Len count := v.Len
// Cap number of elements // Cap number of elements