[Boost-bugs] [Boost C++ Libraries] #13554: NULL deference exception in boost::asio::ip::tcp::resolver::results_type

Subject: [Boost-bugs] [Boost C++ Libraries] #13554: NULL deference exception in boost::asio::ip::tcp::resolver::results_type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-05-01 09:27:44


#13554: NULL deference exception in boost::asio::ip::tcp::resolver::results_type
------------------------------+----------------------------
 Reporter: giacomopoz@… | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.66.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------------
 boost::asio::ip::tcp::resolver::results_type type triggers a NULL
 dereference exception when calling empty() on a default-initialized
 instance.

 How to reproduce:
 - instantiate a new boost::asio::ip::tcp::resolver::results_type class
 instance with the default parameterless constructor
 - call the empty() method, it should return true
 - notice the access violation crash triggered

 Code example:
 {{{#!c++
 #include <boost/asio/ip/tcp.hpp>

 int main(int /*argc*/, char** /*argv*/)
 {
   boost::asio::ip::tcp::resolver::results_type test =
 boost::asio::ip::tcp::resolver::results_type();
   if (test.empty())
     printf("ok");
 }
 }}}

 Boost version: 1.66 Windows x64 vc141

 Issue analysis: empty() is implemented as
 {{{#!c++
 bool empty() const BOOST_ASIO_NOEXCEPT
 {
   return this->values_->empty();
 }
 }}}
 but this->values_ returns NULL when the class is empty. A possible fix
 could be to NULL-check this->values_ and then call ->empty() (if still
 needed at all)
 {{{#!c++
 bool empty() const BOOST_ASIO_NOEXCEPT
 {
   return !this->values_ || this->values_->empty();
 }
 }}}

 Current workaround: I would suggest not to use .empty() at all currently
 but to rely on .begin() == .end() .

 Note that even if the code example above looks quite meaningless, .empty()
 crashes causes issue for example when checking if an address can be
 resolved using ip::basic_resolver::resolve function. The documentation
 states "An empty range is returned if an error occurs" so one expects to
 be able to check if the range is empty.

 P.S.: I had links to sources and documentation but the tracker kept saying
 "Akismet says content is spam". Please fix your tracker.

-- 
Ticket URL: <https://svn.boost.org/trac10/ticket/13554>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-05-01 09:31:33 UTC