Modify

Ticket #8752 (closed Patches: fixed)

Opened 10 months ago

Last modified 7 months ago

Bad check for invalid socket in boost::asio::detail::win_iocp_socket_service<Protocol>::accept()

Reported by: Kevin.Vlack@… 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.

Attachments

Change History

comment:1 follow-up: ↓ 3 Changed 8 months ago by apolukhin

  • Cc antoshkka@… added
  • Type changed from Bugs to Patches

To fix that error, just replace

    if (new_socket.get() >= 0)

with

    if (new_socket.get() == SOCKET_ERROR)

comment:2 Changed 8 months ago by alb

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 in reply to: ↑ 1 Changed 8 months ago by Kevin.Vlack@…

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 Changed 7 months ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

Fixed on trunk in [85745] and [85755]. Merged to release in [85838].

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.