Skip to content

Commit

Permalink
Fix a panic caused by accessing unassigned pointer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cjepson committed Feb 29, 2016
1 parent 3a30ba7 commit 61dd0bc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 !=
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 61dd0bc

Please sign in to comment.