oatpp / oatpp-starter

Oatpp simple-API starter project
https://oatpp.io/
Apache License 2.0
72 stars 35 forks source link

Memory Corruption #18

Open manjus3 opened 2 years ago

manjus3 commented 2 years ago

After adding the following 2 lines in CMakeLists.txt: SET(CMAKE_CXX_COMPILER "clang++") SET (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fstack-check -fstack-protector-strong -finstrument-functions -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -static-libsan")

and building and running executable, I get the following segmentation fault. This also happens in other examples as well. These errors are not detected without adding the above lines.

/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:17:3: runtime error: member access within address 0x7f3e947fa860 which does not point to an object of type 'MyDto::Z__CLASS' (aka 'MyDto') 0x7f3e947fa860: note: object has a possibly invalid vptr: abs(offset to top) too big 72 55 00 00 90 a8 7f 94 3e 7f 00 00 81 79 87 bc 72 55 00 00 f0 fa 45 bd 72 55 00 00 44 e8 84 bc ^~~~~~~ possibly invalid vptr SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:17:3 in AddressSanitizer:DEADLYSIGNAL

==24104==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f3e987fcd4b bp 0x5572bca72b20 sp 0x7f3e947fa4b0 T4) ==24104==The signal is caused by a READ memory access. ==24104==Hint: this fault was caused by a dereference of a high value address (see register values below). Disassemble the provided pc to learn which register was used.

0 0x7f3e987fcd4b in __dynamic_cast (/lib/x86_64-linux-gnu/libstdc++.so.6+0xacd4b) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)

#1 0x5572bc8249fb in __ubsan::checkDynamicType(void*, void*, unsigned long) (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x3379fb) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)
#2 0x5572bc823b42 in HandleDynamicTypeCacheMiss(__ubsan::DynamicTypeCacheMissData*, unsigned long, unsigned long, __ubsan::ReportOptions) ubsan_handlers_cxx.cpp.o
#3 0x5572bc823b0d in __ubsan_handle_dynamic_type_cache_miss (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x336b0d) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)
#4 0x5572bc87a71c in MyDto::Z__PROPERTY_OFFSET_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#5 0x5572bc87a49d in MyDto::Z__PROPERTY_SINGLETON_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#6 0x5572bc87a32c in MyDto::Z__PROPERTY_INIT_message(...) /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#7 0x5572bc8768cf in MyDto::Z__PROPERTY_INITIALIZER_PROXY_message() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#8 0x5572bc876717 in MyDto::MyDto() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:18:3
#9 0x5572bc876618 in void std::_Construct<MyDto>(MyDto*) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_construct.h:119:25
#10 0x5572bc875ca0 in void std::allocator_traits<std::allocator<void> >::construct<MyDto>(std::allocator<void>&, MyDto*) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/alloc_traits.h:635:4
#11 0x5572bc8751b6 in std::_Sp_counted_ptr_inplace<MyDto, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<>(std::allocator<void>) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr_base.h:604:4
#12 0x5572bc874965 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<MyDto, std::allocator<void> >(MyDto*&, std::_Sp_alloc_shared_tag<std::allocator<void> >) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr_base.h:972:6
#13 0x5572bc8745fd in std::__shared_ptr<MyDto, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void> >(std::_Sp_alloc_shared_tag<std::allocator<void> >) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr_base.h:1712:14
#14 0x5572bc874361 in std::shared_ptr<MyDto>::shared_ptr<std::allocator<void> >(std::_Sp_alloc_shared_tag<std::allocator<void> >) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr.h:464:4
#15 0x5572bc873ea9 in std::shared_ptr<std::enable_if<!(is_array<MyDto>::value), MyDto>::type> std::make_shared<MyDto>() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/shared_ptr.h:1009:14
#16 0x5572bc8733be in oatpp::data::mapping::type::DTOWrapper<MyDto> MyDto::createShared<>() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/dto/DTOs.hpp:15:3
#17 0x5572bc872d6a in MyController::root() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/controller/MyController.hpp:27:16
#18 0x5572bc862728 in MyController::Z__PROXY_METHOD_root(std::shared_ptr<oatpp::web::protocol::http::incoming::Request> const&) /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/src/controller/MyController.hpp:26:3
#19 0x5572bc86728c in oatpp::web::server::api::ApiController::Handler<MyController>::handle(std::shared_ptr<oatpp::web::protocol::http::incoming::Request> const&) /usr/local/include/oatpp-1.3.0/oatpp/oatpp/web/server/api/ApiController.hpp:272:16
#20 0x5572bc9284f8 in oatpp::web::server::HttpProcessor::processNextRequest(oatpp::web::server::HttpProcessor::ProcessingResources&, std::shared_ptr<oatpp::web::protocol::http::incoming::Request> const&, oatpp::web::protocol::http::utils::CommunicationUtils::ConnectionState&) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/web/server/HttpProcessor.cpp:117:47
#21 0x5572bc9289ca in oatpp::web::server::HttpProcessor::processNextRequest(oatpp::web::server::HttpProcessor::ProcessingResources&) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/web/server/HttpProcessor.cpp:154:34
#22 0x5572bc9295ef in oatpp::web::server::HttpProcessor::Task::run() /home/manju/tools/oatpp_repos/oatpp/src/oatpp/web/server/HttpProcessor.cpp:262:58
#23 0x5572bc927697 in void std::__invoke_impl<void, void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task>(std::__invoke_memfun_ref, void (oatpp::web::server::HttpProcessor::Task::*&&)(), oatpp::web::server::HttpProcessor::Task&&) /usr/include/c++/12/bits/invoke.h:67:39
#24 0x5572bc9274ad in std::__invoke_result<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task>::type std::__invoke<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task>(void (oatpp::web::server::HttpProcessor::Task::*&&)(), oatpp::web::server::HttpProcessor::Task&&) /usr/include/c++/12/bits/invoke.h:96:40
#25 0x5572bc927376 in void std::thread::_Invoker<std::tuple<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/include/c++/12/bits/std_thread.h:252:26
#26 0x5572bc927179 in std::thread::_Invoker<std::tuple<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task> >::operator()() /usr/include/c++/12/bits/std_thread.h:259:20
#27 0x5572bc927093 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task> > >::_M_run() /usr/include/c++/12/bits/std_thread.h:210:20
#28 0x7f3e9882c2c2  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc2c2) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)
#29 0x7f3e984b5b42 in start_thread nptl/./nptl/pthread_create.c:442:8
#30 0x7f3e985479ff  misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libstdc++.so.6+0xacd4b) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637) in __dynamic_cast Thread T4 created by T1 here:

0 0x5572bc7d0d8c in __interceptor_pthread_create (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x2e3d8c) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)

#1 0x7f3e9882c398 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc398) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)
#2 0x5572bc921bd5 in oatpp::web::server::HttpConnectionHandler::handleConnection(oatpp::provider::ResourceHandle<oatpp::data::stream::IOStream> const&, std::shared_ptr<std::unordered_map<oatpp::data::mapping::type::String, oatpp::data::mapping::type::String, std::hash<oatpp::data::mapping::type::String>, std::equal_to<oatpp::data::mapping::type::String>, std::allocator<std::pair<oatpp::data::mapping::type::String const, oatpp::data::mapping::type::String> > > const> const&) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/web/server/HttpConnectionHandler.cpp:105:113
#3 0x5572bc8e3a4f in oatpp::network::Server::conditionalMainLoop() /home/manju/tools/oatpp_repos/oatpp/src/oatpp/network/Server.cpp:60:50
#4 0x5572bc8e3ee1 in oatpp::network::Server::run(std::function<bool ()>) /home/manju/tools/oatpp_repos/oatpp/src/oatpp/network/Server.cpp:113:24
#5 0x5572bc82a593 in void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()::operator()() const /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/web/ClientServerTestRunner.hpp:104:17
#6 0x5572bc82a2a4 in MyControllerTest::onRun()::$_0 std::__invoke_impl<void, void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()>(std::__invoke_other, void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:14
#7 0x5572bc82a044 in std::__invoke_result<MyControllerTest::onRun()::$_0>::type std::__invoke<void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()>(MyControllerTest::onRun()::$_0&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:96:14
#8 0x5572bc829f88 in void std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:252:13
#9 0x5572bc829e60 in std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:259:11
#10 0x5572bc829be0 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&)::'lambda0'()> > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_thread.h:210:13
#11 0x7f3e9882c2c2  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc2c2) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)

Thread T1 created by T0 here:

0 0x5572bc7d0d8c in __interceptor_pthread_create (/home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/build/my-project-test+0x2e3d8c) (BuildId: df7951fc96518e964f34d4da5a9afa4b46591cd3)

#1 0x7f3e9882c398 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xdc398) (BuildId: 725ef5da52ee6d881f9024d8238a989903932637)
#2 0x5572bc826d69 in void oatpp::test::web::ClientServerTestRunner::run<MyControllerTest::onRun()::$_0>(MyControllerTest::onRun()::$_0 const&, std::chrono::duration<long, std::ratio<1l, 1000000l> > const&) /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/web/ClientServerTestRunner.hpp:103:17
#3 0x5572bc825e00 in MyControllerTest::onRun() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/MyControllerTest.cpp:24:10
#4 0x5572bc8b3a70 in oatpp::test::UnitTest::run(int) /home/manju/tools/oatpp_repos/oatpp/src/oatpp-test/UnitTest.cpp:43:10
#5 0x5572bc825431 in void oatpp::test::UnitTest::runTest<MyControllerTest>(int) /usr/local/include/oatpp-1.3.0/oatpp/oatpp-test/UnitTest.hpp:89:10
#6 0x5572bc824cf5 in runTests() /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/tests.cpp:7:3
#7 0x5572bc824e20 in main /home/manju/tools/oatpp_repos/examples/step-by-step/oatpp-starter/test/tests.cpp:14:3
#8 0x7f3e9844ad8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16