Skip to content

UB in timer constructor #213

@klemens-morgenstern

Description

@klemens-morgenstern

This line

return *timer_service_access::get_scheduler(static_cast<io_context&>(ctx))

assumes that a capy::execution_context is always a corosio::io_context. This is not enforced, and execution_context can be default constructed.

capy::execution_context ec;
timer t(ec);

There's nothing obviously wrong with this code yet it'll cause a SIGSEV.

There are three solutions:

  1. make execution_context abstract so it cannot be constructed this way
  2. throw an exception if it's not an io_context, so it cannot run the scheduler
  3. implicitly construct a thread and let it run the scheduler (what asio does).

Note that Nr.3 would allow us to put an asio::io_context into an capy::any_executor. That would enable users to add corosio functionality to an existing asio app without rewriting everything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions