Skip to content

Commit

Permalink
Fix panic involving nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
bandreghetti committed Nov 12, 2020
1 parent d46cc09 commit a1222b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func NewAsset(m map[string]interface{}) (a Asset, err errors.ICCError) {

a = Asset{}
for k, v := range m {
a[k] = v
if v != nil {
a[k] = v
}
}

// Generate object key
Expand Down
7 changes: 6 additions & 1 deletion assets/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (a Asset) Refs(stub shim.ChaincodeStubInterface) ([]Key, errors.ICCError) {
var keys []Key
for _, subAsset := range assetSubAssets {
subAssetRefInterface, subAssetIncluded := a[subAsset.Tag]
if !subAssetIncluded {
if !subAssetIncluded || subAssetRefInterface == nil {
// If subAsset is not included, no need to append
continue
}
Expand All @@ -46,6 +46,11 @@ func (a Asset) Refs(stub shim.ChaincodeStubInterface) ([]Key, errors.ICCError) {
}

for _, subAssetRefInterface := range subAssetAsArray {
// This is here as a safety measure
if subAssetRefInterface == nil {
continue
}

subAssetRefMap, ok := subAssetRefInterface.(map[string]interface{})
if !ok {
// If subAsset is badly formatted, this method shouldn't have been called
Expand Down

0 comments on commit a1222b9

Please sign in to comment.