Skip to content

wallet: Prevent segfault when sending to unspendable witness#13351

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
maflcko:Mf1806-walletUnspendableWitnessIsMine
Jun 5, 2018
Merged

wallet: Prevent segfault when sending to unspendable witness#13351
maflcko merged 1 commit into
bitcoin:masterfrom
maflcko:Mf1806-walletUnspendableWitnessIsMine

Conversation

@maflcko
Copy link
Copy Markdown
Member

@maflcko maflcko commented May 30, 2018

Previously we wouldn't care about the txnouttype, but after 4e91820 we switch on the type.

@maflcko maflcko added the Wallet label May 30, 2018
Copy link
Copy Markdown
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK fa36aa7.

Comment thread src/script/standard.cpp
vSolutionsRet.push_back(std::move(witnessprogram));
return true;
}
typeRet = TX_NONSTANDARD;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this could be in line 86 above where vSolutionsRet is also cleared/initialized. It also prevents the same problem if in the future early failure returns are added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also drop lines 154 & 155 if you move this up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also drop lines 154 & 155 if you move this up.

That would just make it more fragile. As I understand this function signature, it is meant to return a "pair" of typeRet and vSolutionsRet. Setting that pair should happen as close to the return statement as possible (regardless of early-return or not).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this could be in line 86 above where vSolutionsRet is also cleared/initialized. It also prevents the same problem if in the future early failure returns are added.

This will silence valgrind and thus hide the same problem in the future instead of preventing it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add a vSolutionsRet.clear(); in this line, if people prefer...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just consider best practice to reset outputs in the begin if the function has multiple exits. LGTM still.

@sipa
Copy link
Copy Markdown
Member

sipa commented May 30, 2018

utACK fa36aa7, with or without @promag's suggestion.

@Empact
Copy link
Copy Markdown
Contributor

Empact commented May 30, 2018

utACK fa36aa7

@practicalswift
Copy link
Copy Markdown
Contributor

utACK fa36aa7 modulo @promag:s suggestion – putting it above is more robust.

How was this issue found?

Would running the test suite under valgrind have catched this, or was this condition simply not covered by tests?

@maflcko
Copy link
Copy Markdown
Member Author

maflcko commented May 31, 2018

@practicalswift The gui crashes on point and the tests I added in this commit fail valgrind.

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Jun 5, 2018
…able witness

fa36aa7 wallet: Prevent segfault when sending to unspendable witness (MarcoFalke)

Pull request description:

  Previously we wouldn't care about the `txnouttype`, but after 4e91820 we `switch` on the type.

Tree-SHA512: 6b597aba80cb43881671ad7b3a4ad97753864e8005a05c23fdd8ee79953483c08f241b5c392a9b494298eadc5cfba895b0480d916ef4f11d122fd6196f31b84a
@maflcko maflcko merged commit fa36aa7 into bitcoin:master Jun 5, 2018
@maflcko maflcko deleted the Mf1806-walletUnspendableWitnessIsMine branch June 5, 2018 15:55
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants