Skip to content

Commit

Permalink
fix: avoid panic on CBOR decode of CardanoDnsDomain (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney authored Jul 10, 2024
1 parent 5ad53a2 commit eca7946
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions cdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
type CardanoDnsTtl uint

type CardanoDnsDomain struct {
// This allows the type to be used with cbor.DecodeGeneric
cbor.StructAsArray
Origin []byte
Records []CardanoDnsDomainRecord
AdditionalData CardanoDnsMaybe[any]
Expand Down Expand Up @@ -53,17 +55,7 @@ func (c *CardanoDnsDomain) UnmarshalCBOR(cborData []byte) error {
if tmpData.Constructor() != 1 {
return fmt.Errorf("unexpected constructor index: %d", tmpData.Constructor())
}
tmpFields := tmpData.Fields()
c.Origin = tmpFields[0].(cbor.ByteString).Bytes()
for _, record := range tmpFields[1].([]any) {
recordConstr := record.(cbor.Constructor)
var tmpRecord CardanoDnsDomainRecord
if _, err := cbor.Decode(recordConstr.Cbor(), &tmpRecord); err != nil {
return err
}
c.Records = append(c.Records, tmpRecord)
}
return nil
return cbor.DecodeGeneric(tmpData.FieldsCbor(), c)
}

type CardanoDnsDomainRecord struct {
Expand Down

0 comments on commit eca7946

Please sign in to comment.