proc: do not try to load a non-empty slice if the base address is 0 (#3295)

This commit is contained in:
Alessandro Arzilli
2023-03-01 20:27:06 +01:00
committed by GitHub
parent 372552bf1f
commit 212c2002bb
3 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"go/constant"
"math"
"reflect"
"runtime"
"time"
"unsafe"
@ -371,6 +372,10 @@ func main() {
namedA1 := astructName1{12, 45}
namedA2 := astructName2{13, 46}
badslice := []int{1, 2, 3}
h := (*reflect.SliceHeader)(unsafe.Pointer(&badslice))
h.Data = 0
var amb1 = 1
runtime.Breakpoint()
for amb1 := 0; amb1 < 10; amb1++ {
@ -381,5 +386,5 @@ func main() {
longslice := make([]int, 100, 100)
runtime.Breakpoint()
fmt.Println(i1, i2, i3, p1, pp1, amb1, s1, s3, a0, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, m4, m5, upnil, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, ni64, pinf, ninf, nan, zsvmap, zsslice, zsvar, tm, rettm, errtypednil, emptyslice, emptymap, byteslice, bytestypeslice, runeslice, bytearray, bytetypearray, runearray, longstr, nilstruct, as2, as2.NonPointerRecieverMethod, s4, iface2map, issue1578, ll, unread, w2, w3, w4, w5, longarr, longslice, val, m6, m7, cl, tim1, tim2, typedstringvar, namedA1, namedA2, astructName1(namedA2))
fmt.Println(i1, i2, i3, p1, pp1, amb1, s1, s3, a0, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr, ch1, chnil, m1, mnil, m2, m3, m4, m5, upnil, up1, i4, i5, i6, err1, err2, errnil, iface1, iface2, ifacenil, arr1, parr, cpx1, const1, iface3, iface4, recursive1, recursive1.x, iface5, iface2fn1, iface2fn2, bencharr, benchparr, mapinf, mainMenu, b, b2, sd, anonstruct1, anonstruct2, anoniface1, anonfunc, mapanonstruct1, ifacearr, efacearr, ni8, ni16, ni32, ni64, pinf, ninf, nan, zsvmap, zsslice, zsvar, tm, rettm, errtypednil, emptyslice, emptymap, byteslice, bytestypeslice, runeslice, bytearray, bytetypearray, runearray, longstr, nilstruct, as2, as2.NonPointerRecieverMethod, s4, iface2map, issue1578, ll, unread, w2, w3, w4, w5, longarr, longslice, val, m6, m7, cl, tim1, tim2, typedstringvar, namedA1, namedA2, astructName1(namedA2), badslice)
}

View File

@ -1656,6 +1656,10 @@ func (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) {
v.Unreadable = errors.New("Negative array length")
return
}
if v.Base == 0 && v.Len > 0 {
v.Unreadable = errors.New("non-zero length array with nil base")
return
}
count := v.Len
// Cap number of elements

View File

@ -829,6 +829,9 @@ func TestEvalExpression(t *testing.T) {
// Conversions to ptr-to-ptr types
{`**(**runtime.hmap)(uintptr(&m1))`, false, ``, ``, "runtime.hmap", nil},
// Malformed values
{`badslice`, false, `(unreadable non-zero length array with nil base)`, `(unreadable non-zero length array with nil base)`, "[]int", nil},
}
ver, _ := goversion.Parse(runtime.Version())