From 61dd0bce67d6adf104d8a9472d5cfffc558cc1ef Mon Sep 17 00:00:00 2001 From: cjepson Date: Mon, 29 Feb 2016 13:47:04 -0500 Subject: [PATCH] Fix a panic caused by accessing unassigned pointer This bug was introduced with the fix for checkBlockForHidden votes. One of the consistency checks fails if the template is uninitialized. The unitialized pointer is now caught and the function will safely return. --- blockmanager.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index 29ac5215..85fd1ae1 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -946,7 +946,6 @@ func (b *blockManager) checkBlockForHiddenVotes(block *dcrutil.Block) { // the parent template hasn't yet been updated, so we may // need to use the current template. var template *BlockTemplate - if b.cachedCurrentTemplate != nil { if b.cachedCurrentTemplate.height == block.Height() { @@ -961,6 +960,11 @@ func (b *blockManager) checkBlockForHiddenVotes(block *dcrutil.Block) { } } + // No template to alter. + if template == nil { + return + } + // Make sure that the template has the same parent // as the new block. if template.block.Header.PrevBlock != @@ -1011,9 +1015,6 @@ func (b *blockManager) checkBlockForHiddenVotes(block *dcrutil.Block) { newVotes = append(newVotes, vote) } } - } else { - // We have no template, so nothing to update. - return } // Check the length of the reconstructed voter list for