Skip to content
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 multi.Errors panic on nil append #53

Merged

Conversation

jeremy-asher
Copy link
Contributor

This extends the nil check for multi.Errors to the Append function to make sure
nil errors do not end up in the slice, causing a panic when the error string is
generated.

I ran into this panic with the QueryBlockByTxID function. The QueryBlock* series of functions lack a nil check before appending errors:

tprs, errs := queryChaincode(reqCtx, c.chName, cir, targets, verifier)
responses, errors := getConfigBlocks(tprs)
errs = multi.Append(errs, errors)

tprs, errs := queryChaincode(reqCtx, c.chName, cir, targets, verifier)
responses, errors := getConfigBlocks(tprs)
errs = multi.Append(errs, errors)

tprs, errs := queryChaincode(reqCtx, c.chName, cir, targets, verifier)
responses, errors := getConfigBlocks(tprs)
errs = multi.Append(errs, errors)

The tests for these functions don't seem to be capable of handling these edge cases, but I added a test for this specific case to the multi test suite. This test fails on the current master (and panics when printing the failure).

If it is preferred, I can just add some nil checks on those functions, but this seemed like a simpler, more universal solution and in the spirit of how the New function works:

for _, err := range errs {
if err != nil {
errors = append(errors, err)
}
}

@jeremy-asher jeremy-asher requested a review from a team as a code owner February 18, 2020 23:08
@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

Merging #53 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #53      +/-   ##
==========================================
+ Coverage   74.61%   74.66%   +0.05%     
==========================================
  Files         183      183              
  Lines       12788    12790       +2     
==========================================
+ Hits         9542     9550       +8     
+ Misses       2304     2300       -4     
+ Partials      942      940       -2
Impacted Files Coverage Δ
pkg/common/errors/multi/multi.go 100% <100%> (ø) ⬆️
pkg/util/concurrent/lazyref/lazyref.go 96.31% <0%> (+3.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be7b275...19145fd. Read the comment docs.

This extends the nil check for multi.Errors to the Append function to make sure
nil errors do not end up in the slice, causing a panic when the error string is
generated.

Signed-off-by: Jeremy Asher <[email protected]>
@jeremy-asher jeremy-asher force-pushed the fix-nil-in-multi-error-append branch from 4437f47 to 19145fd Compare February 18, 2020 23:54
@alikic alikic merged commit ae164c9 into hyperledger:master Feb 19, 2020
@jeremy-asher jeremy-asher deleted the fix-nil-in-multi-error-append branch February 19, 2020 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants