Skip to content

SegFault on imap connections with timeout #220

Description

@alex-aparin

Hello. I have encountered occasional segfault related with send_async method. It's seems like there is case of inproper canceling async_write operation by timeout. Suspicious code

I suppose in the case of timeout async_write operation should be canceled explicitly, otherwise dialog_error exception raised from wait_async will clean stack and buffer will point to corrupted memory.

I have changed locally wait_async function which solved problem

    void dialog::wait_async(const bool& has_op, const bool& op_error, const char* expired_msg, const char* op_msg, const error_code& error)
    {
        do
        {
            if (timer_expired_)
            {
                socket_->cancel();                      // cancel the pending async op
                while (!has_op && !op_error)            // drain its completion handler
                    ios_.run_one();                     // (fires with operation_aborted)
                throw dialog_error(expired_msg, error.message());
            }
            if (op_error)
                throw dialog_error(op_msg, error.message());
            ios_.run_one();
        }
        while (!has_op);
    }

It's no so good solution, but I hope it better highlights the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions