Page MenuHomePhabricator

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

Authored by majcosta on Jul 27 2020, 18:17.

Details

Reviewers
deadalnix
Group Reviewers
Restricted Project
Commits
rABCdc175d1eeef2: [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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jul 27 2020, 19:06

[Bot Message]
One or more PR numbers were detected in the summary.
Links to those PRs have been inserted into the summary for reference.