-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lib/blocktree): fix potential nil pointer dereference in HighestCommonAncestor
, core handleBlocksAsync
#1993
Changes from all commits
39de2d7
a07d83d
178f727
6f3fd63
beb2e47
a31ed8d
71c0afe
5f1374a
4d740e1
cee1fe6
c3bc8af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,17 +55,20 @@ func (n *node) createTree(tree gotree.Tree) { | |
|
||
// getNode recursively searches for a node with a given hash | ||
func (n *node) getNode(h common.Hash) *node { | ||
if n == nil { | ||
return nil | ||
} | ||
Comment on lines
+58
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit Does this happen? Should we check at the caller level if node is nil or not instead of calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it shouldn't happen, but I'd rather have this check here just to be safe... do you know of a good method for dealing with things like this, where it shouldn't happen but if it does it's really bad? kinda what I thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, panics are when you can't break a function signature. For example if you have an exported, public I usually try to return an error instead of panicing. In this situation though, I think you are returning a The best long term solution is testing depth and coverage, but that's not an easy task! |
||
|
||
if n.hash == h { | ||
return n | ||
} else if len(n.children) == 0 { | ||
return nil | ||
} else { | ||
for _, child := range n.children { | ||
if n := child.getNode(h); n != nil { | ||
return n | ||
} | ||
} | ||
|
||
for _, child := range n.children { | ||
if n := child.getNode(h); n != nil { | ||
return n | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO with an issue number to fix the skipped tests? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep I'll add it to here: #1026