From bbecbc47cd3762e0fea165a1252449fcc68e76e3 Mon Sep 17 00:00:00 2001 From: Stephen Searles Date: Sat, 19 Nov 2016 00:58:13 -0800 Subject: [PATCH] search: fix panic when claim and permanode have no attributes. fixes #881 Change-Id: Ifdea54a56bf879ca418763617acf7bd2b9159dad --- pkg/index/location.go | 7 ++++++- pkg/index/util.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/index/location.go b/pkg/index/location.go index 84a0f66c2..0f61df648 100644 --- a/pkg/index/location.go +++ b/pkg/index/location.go @@ -149,5 +149,10 @@ func (pa permAttr) get(attr string) string { } return "" } - return claimsIntfAttrValue(pa.claims, attr, pa.at, pa.signerFilter) + + if pa.claims != nil { + return claimsIntfAttrValue(pa.claims, attr, pa.at, pa.signerFilter) + } + + return "" } diff --git a/pkg/index/util.go b/pkg/index/util.go index 740b8d113..e0308ce0e 100644 --- a/pkg/index/util.go +++ b/pkg/index/util.go @@ -77,7 +77,13 @@ type claimPtrSlice []*camtypes.Claim func (s claimPtrSlice) Len() int { return len(s) } func (s claimPtrSlice) Claim(i int) *camtypes.Claim { return s[i] } +// claimsIntfAttrValue finds the value of an attribute in a list of claims +// or empty string if not found. claims must be non-nil. func claimsIntfAttrValue(claims claimsIntf, attr string, at time.Time, signerFilter blob.Ref) string { + if claims == nil { + panic("nil claims argument in claimsIntfAttrValue") + } + if at.IsZero() { at = time.Now() }