asio icon indicating copy to clipboard operation
asio copied to clipboard

asio::error::ssl_errors should be scoped to prevent UB

Open anarthal opened this issue 9 months ago • 1 comments

The enumeration type is defined as:

enum ssl_errors
{
  // Error numbers are those produced by openssl.
};
inline boost::system::error_code make_error_code(ssl_errors e);

I get that errors belonging to this category are really OpenSSL error codes.

Now, I wrote something like this in my unit tests:

error_code ec {static_cast<asio::error::ssl_errors>(1623)}; // 1623 simulates an OpenSSL error

While this builds, this is flagged as undefined behavior by ubsan, as 1623 is not a valid enumerator. This wouldn't happen if ssl_errors would have been an enum class, instead.

Since ssl_errors doesn't have any enumerator, it looks like any such casts is a recipe for UB. I think the right thing to do would be converting the type to an enum class.

anarthal avatar Apr 30 '24 10:04 anarthal