Opened 9 years ago
Closed 9 years ago
#8752 closed Patches (fixed)
Bad check for invalid socket in boost::asio::detail::win_iocp_socket_service<Protocol>::accept()
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | To Be Determined | Component: | asio |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: | antoshkka@… |
Description
(See line 434 in boost/asio/detail/win_iocp_socket_service.hpp).
At the end of the function boost::asio::detail::win_iocp_socket_service<Protocol>::accept() there is a check for an valid SOCKET handle by checking if the result is >= 0.
In recent Winsock implementations the SOCKET is typedef'd as an unsigned type (UINT_PTR), so this check for >= 0 will succeed even for invalid sockets.
If the preceding accept() operation fails and returns an invalid socket, the consequence of using it in subsequent operations is an ugly anonymous exception.
Change History (4)
follow-up: 3 comment:1 by , 9 years ago
Cc: | added |
---|---|
Type: | Bugs → Patches |
comment:2 by , 9 years ago
Or better platform independent constant boost::asio::detail::socket_error_retval. But SOCKET_ERROR is OK too since win_iocp_socket_service.cpp is windows-only.
comment:3 by , 9 years ago
Replying to apolukhin:
To fix that error, just replace
if (new_socket.get() >= 0)with
if (new_socket.get() == SOCKET_ERROR)
Since that line checks if the socket is valid*, I believe that should be:
if (new_socket.get() != SOCKET_ERROR)
comment:4 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
To fix that error, just replace
with