Bugfix: Require OrderedTxItems to provide properly scoped accounting entry list #1774

pull luke-jr wants to merge 1 commits into bitcoin:master from luke-jr:refactor_times changing 3 files +12 −6
  1. luke-jr commented at 10:14 PM on September 1, 2012: member

    OrderedTxItems returns a multimap of pointers, but needs a place to store the actual CAccountingEntries it points to. It had been using a stack item, which was clobbered as soon as it returned, resulting in undefined behaviour.

    This fixes at least bug #1768.

  2. gavinandresen commented at 10:22 PM on September 1, 2012: contributor

    ACK. makes valgrind happy again.

  3. in src/wallet.cpp:None in b153ff0776 outdated
     304 | @@ -306,7 +305,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
     305 |          CWalletTx* wtx = &((*it).second);
     306 |          txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0)));
     307 |      }
     308 | -    list<CAccountingEntry> acentries;
     309 | +    acentries.empty();
    


    laanwj commented at 6:35 AM on September 2, 2012:

    Don't you mean .clear()?


    luke-jr commented at 7:33 AM on September 2, 2012:

    Yes, oops.

  4. laanwj commented at 6:44 AM on September 2, 2012: member

    I agree that this would solve the immediate problem. std::list (unlike std::vector) does not invalidate iterators when items are added, so it is safe to keep pointers to items in it.

    I do think the solution is a bit strange, but maybe it's just me. Why not return a type from OrderedTxItems that has the actual CAccountingEntry instead of one that has pointers to another (temporary) structure, which is being built at the same time?

  5. luke-jr commented at 7:36 AM on September 2, 2012: member

    @laanwj It does feel strange to me, but I failed to think up a better way short of trying to rewrite it in some other paradigm. Maybe boost::variant would work better (most of the CAccountingEntry pointers are NULL), but I'm not comfortable with adding that into the mix myself this late in the release cycle.

  6. laanwj commented at 7:42 AM on September 2, 2012: member

    Yes, this is the simplest solution for now, that's for sure. Maybe add a (doxygen) comment to CWallet::OrderedTxItems that warns of the dangers, instead of only at the callsite in wallet.h.

  7. Bugfix: Require OrderedTxItems to provide properly scoped accounting entry list
    OrderedTxItems returns a multimap of pointers, but needs a place to store the actual CAccountingEntries it points to.
    It had been using a stack item, which was clobbered as soon as it returned, resulting in undefined behaviour.
    This fixes at least bug #1768.
    ddb709e9de
  8. luke-jr commented at 8:02 AM on September 2, 2012: member

    Like that?

  9. laanwj commented at 10:22 AM on September 2, 2012: member

    Yes. ACK

  10. gmaxwell commented at 5:36 PM on September 2, 2012: contributor

    ACK. (oops. clicked the wrong button)

  11. gmaxwell closed this on Sep 2, 2012

  12. gmaxwell reopened this on Sep 2, 2012

  13. gavinandresen referenced this in commit eaf00a3a5d on Sep 2, 2012
  14. gavinandresen merged this on Sep 2, 2012
  15. gavinandresen closed this on Sep 2, 2012

  16. owlhooter referenced this in commit 6915ee45e6 on Oct 10, 2018
  17. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 15:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me