mirror of
https://github.com/json-iterator/go.git
synced 2025-04-01 21:24:21 +02:00
fix #206, do not allow nil pointer as unmarshal input
This commit is contained in:
parent
13f86432b8
commit
e0df39fda2
@ -233,6 +233,10 @@ func (iter *Iterator) ReadVal(obj interface{}) {
|
||||
return
|
||||
}
|
||||
e := (*emptyInterface)(unsafe.Pointer(&obj))
|
||||
if e.word == nil {
|
||||
iter.ReportError("ReadVal", "can not read into nil pointer")
|
||||
return
|
||||
}
|
||||
decoder.Decode(e.word, iter)
|
||||
}
|
||||
|
||||
|
@ -136,3 +136,14 @@ func Test_valid(t *testing.T) {
|
||||
should.True(Valid([]byte(`{}`)))
|
||||
should.False(Valid([]byte(`{`)))
|
||||
}
|
||||
|
||||
func Test_nil_pointer(t *testing.T) {
|
||||
should := require.New(t)
|
||||
data := []byte(`{"A":0}`)
|
||||
type T struct {
|
||||
X int
|
||||
}
|
||||
var obj *T
|
||||
err := Unmarshal(data, obj)
|
||||
should.NotNil(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user