Opened 10 years ago

Closed 8 years ago

#8295 closed Bugs (fixed)

`libs/asio/test/buffer.cpp` might fail because of an undefined behavior

Reported by: Ai Azuma <ai.azuma@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

The invocation of buffer_copy at line 173 in libs/asio/test/buffer.cpp might cause an undefined behavior. Therefore, the test case might fail in any reason even if the invocation is enclosed by a try block.

More specifically, this test case fails when compiling on GCC 4.8.0 with AddressSanitizer (-fsanitize=address). The error report created by AddressSanitizer is as follows;

=================================================================
==28915== ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x7fff9eceff20,0x7fff9ecf02a0) and [0x7fff9ecefea0, 0x7fff9ecf0220) overlap
    #0 __interceptor_memcpy at /home/cryolite/work/intro/gcc-4.8-20130310/libsanitizer/asan/asan_interceptors.cc:285
    #1 boost::asio::buffer_copy(boost::asio::mutable_buffer const&, boost::asio::const_buffer const&) at /home/cryolite/local/boost/latest/libs/asio/test/../../../boost/asio/buffer.hpp:1291
    #2 boost::asio::buffer_copy(boost::asio::mutable_buffers_1 const&, boost::asio::mutable_buffer const&) at /home/cryolite/local/boost/latest/libs/asio/test/../../../boost/asio/buffer.hpp:1466
    #3 buffer_compile::test() at /home/cryolite/local/boost/latest/libs/asio/test/buffer.cpp:173
    (The rest of the backtrace is omitted because they are essentially irrelevant.)

(The backtrace has been translated into corresponding source file lines.)

As the error report indicates, buffer_copy in line 173 comes down to memcpy between overlapped memory regions. This is ill-formed, and an undefined behavior might forbid the test case to continue.

In addition to this problem, the documentation for buffer_copy does not clearly mention whether the source and destination regions of buffer_copy can be overlapped or not. If it is not allowed as the implementation (the use of memcpy) indicates, it would be better to document it clearly.

Change History (1)

comment:1 by chris_kohlhoff, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.