Slice of pointers can json unmarshal with nil values
jtraglia opened this issue · 1 comments
Hi there. When unmarshaling structures with a slice of pointers, we do not check that the values are not nil. Therefore, it's possible for these values to be nil after unmarshaling and no error is reported. Depending on how the result is used, this could result in a nil dereference error. This is a pretty common pattern here, but for example, this structure:
go-eth2-client/api/v1/deneb/blindedbeaconblockbody_json.go
Lines 34 to 38 in e06a551
When unmarshaling, we only check if the slice is nil, not the values:
go-eth2-client/api/v1/deneb/blindedbeaconblockbody_json.go
Lines 105 to 108 in e06a551
One potential solution would to make these non-pointer types. Why are these pointers? The other solution would be to add the necessary nil checks when unmarshaling, which could be a lot of work.