mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/xml: check nil pointer in DecodeElement
Fixes #53350
Change-Id: Id5e1f4016db5f1d4349ee1a76a9dfe3aeae83cee
GitHub-Last-Rev: 45add12161
GitHub-Pull-Request: golang/go#53407
Reviewed-on: https://go-review.googlesource.com/c/go/+/412634
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Rakoczy <alex@golang.org>
This commit is contained in:
parent
f571518139
commit
606c6c371a
2 changed files with 19 additions and 0 deletions
|
|
@ -148,6 +148,10 @@ func (d *Decoder) DecodeElement(v any, start *StartElement) error {
|
|||
if val.Kind() != reflect.Pointer {
|
||||
return errors.New("non-pointer passed to Unmarshal")
|
||||
}
|
||||
|
||||
if val.IsNil() {
|
||||
return errors.New("nil pointer passed to Unmarshal")
|
||||
}
|
||||
return d.unmarshal(val.Elem(), start)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1079,3 +1079,18 @@ func TestUnmarshalWhitespaceAttrs(t *testing.T) {
|
|||
t.Fatalf("whitespace attrs: Unmarshal:\nhave: %#+v\nwant: %#+v", v, want)
|
||||
}
|
||||
}
|
||||
|
||||
// golang.org/issues/53350
|
||||
func TestUnmarshalIntoNil(t *testing.T) {
|
||||
type T struct {
|
||||
A int `xml:"A"`
|
||||
}
|
||||
|
||||
var nilPointer *T
|
||||
err := Unmarshal([]byte("<T><A>1</A></T>"), nilPointer)
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("no error in unmarshalling")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue