chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

UB in impl/awaitable.hpp #1450

Closed linuxnyasha closed 2 months ago

linuxnyasha commented 3 months ago
template <typename T, typename Executor>
class awaitable_frame

contains

alignas(T) unsigned char result_[sizeof(T)]; 
  T get()
  {
    this->caller_ = nullptr;
    this->rethrow_exception();
    return std::move(*static_cast<T*>(static_cast<void*>(result_)));
  }
    ~awaitable_frame()
  {
    if (has_result_)
      static_cast<T*>(static_cast<void*>(result_))->~T();
  }

But a simple static cast is used into a void and to the T, but the pointer from this does not point to the object, see [basic.life], so you need to std::launder it before using.