HomePhabricator

[backport#16572] wallet: Fix Char as Bool in Wallet

Description

[backport#16572] wallet: Fix Char as Bool in Wallet

Summary:
Fix Char as Bool in interfaces (Jeremy Rubin)

Pull request description:

In a few places in src/wallet/wallet.h, we use a char when semantically we want a bool.

This is kind of an issue because it means we can unserialize the same transaction with different fFromMe flags (as differing chars) and evaluate the following section in wallet/wallet.cpp
```c++
        if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe)
         {
             wtx.fFromMe = wtxIn.fFromMe;
             fUpdated = true;
         }
```
incorrectly (triggering an fUpdated where both fFromMe values represent true, via different chars).

I don't think this is a vulnerability, but it's just a little messy and unsemantic, and could lead to issues with stored wtxIns not being findable in a map by their hash.

The serialize/unserialize code for bool internally uses a char, so it should be safe to make this substitution.

NOTE: Technically, this is a behavior change -- I haven't checked too closely that nowhere is depending on storing information in this char. Theoretically, this could break something because after this change a tx unserialized with such a char would preserve it's value, but now it is converted to a ~true~ canonical bool.

https://github.com/bitcoin/bitcoin/pull/16572/commits/2dbfb37b407ed23b517f507d78fb77334142dce5


Backport of Core PR16572

Test Plan:

ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7046

Details

Provenance
fanquake <fanquake@gmail.com>Authored on Aug 21 2019, 07:06
majcostaCommitted on Jul 27 2020, 19:17
majcostaPushed on Jul 27 2020, 19:17
Reviewer
Restricted Project
Differential Revision
D7046: [backport#16572] wallet: Fix Char as Bool in Wallet
Parents
rABC798bd152c075: Add golang to the CI base image
Branches
Unknown
Tags
Unknown