Boost C++ Libraries: Ticket #8752: Bad check for invalid socket in boost::asio::detail::win_iocp_socket_service<Protocol>::accept() https://svn.boost.org/trac10/ticket/8752 <p> (See line 434 in boost/asio/detail/win_iocp_socket_service.hpp). </p> <p> At the end of the function boost::asio::detail::win_iocp_socket_service&lt;Protocol&gt;::accept() there is a check for an valid SOCKET handle by checking if the result is &gt;= 0. </p> <p> In recent Winsock implementations the SOCKET is typedef'd as an unsigned type (UINT_PTR), so this check for &gt;= 0 will succeed even for invalid sockets. </p> <p> If the preceding accept() operation fails and returns an invalid socket, the consequence of using it in subsequent operations is an ugly anonymous exception. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8752 Trac 1.4.3 Antony Polukhin Wed, 21 Aug 2013 13:31:52 GMT type changed; cc set https://svn.boost.org/trac10/ticket/8752#comment:1 https://svn.boost.org/trac10/ticket/8752#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">antoshkka@…</span> added </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> <p> To fix that error, just replace </p> <pre class="wiki"> if (new_socket.get() &gt;= 0) </pre><p> with </p> <pre class="wiki"> if (new_socket.get() == SOCKET_ERROR) </pre> Ticket alb Wed, 21 Aug 2013 16:41:13 GMT <link>https://svn.boost.org/trac10/ticket/8752#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8752#comment:2</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>Kevin.Vlack@…</author> <pubDate>Fri, 23 Aug 2013 13:05:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8752#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8752#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/8752#comment:1" title="Comment 1">apolukhin</a>: </p> <blockquote class="citation"> <p> To fix that error, just replace </p> <pre class="wiki"> if (new_socket.get() &gt;= 0) </pre><p> with </p> <pre class="wiki"> if (new_socket.get() == SOCKET_ERROR) </pre></blockquote> <p> Since that line checks if the socket is valid*, I believe that should be: </p> <pre class="wiki">if (new_socket.get() != SOCKET_ERROR) </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Tue, 01 Oct 2013 08:16:10 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8752#comment:4 https://svn.boost.org/trac10/ticket/8752#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed on trunk in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85745" title="Fix comparison used to test for a successful synchronous accept.">[85745]</a> and <a class="changeset" href="https://svn.boost.org/trac10/changeset/85755" title="Fix another socket descriptor comparison that doesn't work correctly ...">[85755]</a>. Merged to release in <a class="changeset" href="https://svn.boost.org/trac10/changeset/85838" title="Merge asio from trunk. ...">[85838]</a>. </p> Ticket