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: | 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.
Fixed on 'develop' in 2114f2d17b535c53cf1f1ef086676335c87e388d and fd8471c5d69425f0fd47ab4bef604c197d30dabc.
Merged to 'master' in 4e1e7d731fcc5c0104567856de476f7ce8806d72.