Skip to content

potential stack corruption when misusing "crank" #528

Closed

Description

@MonsieurNicolas

There are several places in the code that fallow this pattern:

        bool done = false;
        asio::error_code ec;
        uint32_t lclNum = mApp.getLedgerManager().getLastClosedLedgerNum();
        uint32_t ledgerNum = mApp.getLedgerManager().getLedgerNum();
        hm.publishHistory([&done, &ec](asio::error_code const& ec2)
                          {
                              ec = ec2;
                              done = true;
                          });
        while (!done && mApp.getClock().crank(false))
            ;

The problem is that some async operations such as retrieving data from a remote are not events in the queue, which may cause the "crank" call to return 0.
In that case, the boolean "done" may get out of scope but the callback is still pending (it's just a matter of somebody else calling "crank").

When the callback is finally called, the stack will be overwritten when the callback performs "done = true" in the example above.

The pattern should probably be changed to

       bool done = false;
        asio::error_code ec;
        uint32_t lclNum = mApp.getLedgerManager().getLastClosedLedgerNum();
        uint32_t ledgerNum = mApp.getLedgerManager().getLedgerNum();
        hm.publishHistory([&done, &ec](asio::error_code const& ec2)
                          {
                              ec = ec2;
                              done = true;
                          });
        while (!done)
        {
             mApp.getClock().crank(false));
             // maybe a "sleep" of some sort to avoid spinning the thread
        }

Activity

  1. added this to the milestone on Jun 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions