Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have better ubsan stack trace #816

Closed
wants to merge 1 commit into from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Dec 30, 2024

Not intended to be merged.

It seems .has_value() checks are needed for undefined sanitizer to pass. Recommend enabling ADA_SANITIZE_UNDEFINED=ON to have a better stack trace. (PS: disable ADA_SANITIZE)

Stack trace after these changes

Load of value 6, which is not a valid value for type 'bool'
  at 0x5555555ffd3f tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::has_value() const
  at 0x55555560552c ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)
  at 0x5555555ce8b6 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x5555557be942 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b620c void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x55555578eab1 testing::Test::Run() (gtest.cc:2713)
  at 0x55555578f56f testing::TestInfo::Run() (gtest.cc:2859)
  at 0x55555578ff37 testing::TestSuite::Run() (gtest.cc:3037)
  at 0x55555579ff5d testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:5967)
  at 0x5555557bfe9f bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b75a4 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2674)
  at 0x55555579e449 testing::UnitTest::Run() (gtest.cc:5546)
  at 0x55555577a3fd RUN_ALL_TESTS() (gtest.h:2334)
  at 0x55555577a3e5 main (gtest_main.cc:64)
  at 0x7ffff702a1c9 __libc_start_call_main (libc_start_call_main.h:58)
  at 0x7ffff702a28a __libc_start_main_impl (libc-start.c:360)
  at 0x5555555cde24 _start

Before

Load of value 96, which is not a valid value for type 'bool'
  at 0x55555562d9ac ada::url_pattern_component::url_pattern_component(ada::url_pattern_component&&)
  at 0x555555706c03 tl::detail::expected_storage_base<ada::url_pattern_component, ada::url_pattern_errors, false, true>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:616)
  at 0x5555556fecce tl::detail::expected_operations_base<ada::url_pattern_component, ada::url_pattern_errors>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:727)
  at 0x5555556fecf8 tl::detail::expected_copy_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:987)
  at 0x5555556fed22 tl::detail::expected_move_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:1023)
  at 0x5555556fed4c tl::detail::expected_copy_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:1058)
  at 0x5555556fed76 tl::detail::expected_move_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:1098)
  at 0x5555556feda9 tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::expected<ada::url_pattern_component, (void*)0>(tl::in_place_t, ada::url_pattern_component&&) (expected.h:1608)
  at 0x5555556f3f1b tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::expected<ada::url_pattern_component, (void*)0, (void*)0>(ada::url_pattern_component&&) (expected.h:1738)
  at 0x5555556c2a1c tl::expected<ada::url_pattern_component, ada::url_pattern_errors> ada::url_pattern_component::compile<tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >)>(std::basic_string_view<char, std::char_traits<char> >, tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >), ada::url_pattern_compile_component_options&) (url_pattern.cpp:540)
  at 0x55555560363d ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)
  at 0x5555555ce8b6 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x5555557be8ac void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b6176 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x55555578ea1b testing::Test::Run() (gtest.cc:2713)
  at 0x55555578f4d9 testing::TestInfo::Run() (gtest.cc:2859)
  at 0x55555578fea1 testing::TestSuite::Run() (gtest.cc:3037)
  at 0x55555579fec7 testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:5967)
  at 0x5555557bfe09 bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b750e bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2674)
  at 0x55555579e3b3 testing::UnitTest::Run() (gtest.cc:5546)
  at 0x55555577a367 RUN_ALL_TESTS() (gtest.h:2334)
  at 0x55555577a34f main (gtest_main.cc:64)
  at 0x7ffff702a1c9 __libc_start_call_main (libc_start_call_main.h:58)
  at 0x7ffff702a28a __libc_start_main_impl (libc-start.c:360)
  at 0x5555555cde24 _start


Note: If you enable ADA_SANITIZE_WITHOUT_LEAKS you get an a lot different stack trace.

Stack-buffer-overflow on address 0x7fffffffbac0 at pc 0x7ffff78fb303 bp 0x7fffffffa690 sp 0x7fffffff9e38
WRITE of size 2 at 0x7fffffffbac0 thread T0
  at 0x7ffff78fb302 memcpy (sanitizer_common_interceptors_memintrinsics.inc:115)
  at 0x55555559f858 std::char_traits<char>::copy(char*, char const*, unsigned long)
  at 0x5555555bfe63 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) (basic_string.h:683)
  at 0x5555556675b7 ada::url_pattern_component::url_pattern_component(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool) (url_pattern.h:208)
  at 0x555555732840 tl::detail::expected_storage_base<ada::url_pattern_component, ada::url_pattern_errors, false, true>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:616)
  at 0x55555571711c tl::detail::expected_operations_base<ada::url_pattern_component, ada::url_pattern_errors>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:727)
  at 0x555555717264 tl::detail::expected_copy_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:987)
  at 0x5555557173ac tl::detail::expected_move_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1023)
  at 0x5555557174f4 tl::detail::expected_copy_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1058)
  at 0x55555571763c tl::detail::expected_move_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1098)
  at 0x555555717723 tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1608)
  at 0x5555556c7900 tl::expected<ada::url_pattern_component, ada::url_pattern_errors> ada::url_pattern_component::compile<tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >)>(std::basic_string_view<char, std::char_traits<char> >, tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >), ada::url_pattern_compile_component_options&) (url_pattern.cpp:542)
  at 0x5555555b9dcb ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)
  at 0x5555555876a9 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x5555558604de void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x555555857da8 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x55555583064d testing::Test::Run() (gtest.cc:2713)
  at 0x55555583110b testing::TestInfo::Run() (gtest.cc:2859)
  at 0x555555831ad3 testing::TestSuite::Run() (gtest.cc:3037)
  at 0x555555841af9 testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:5967)
  at 0x555555861a3b bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2638)
  at 0x555555859140 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2674)
  at 0x55555583ffe5 testing::UnitTest::Run() (gtest.cc:5546)
  at 0x55555581bf99 RUN_ALL_TESTS() (gtest.h:2334)
  at 0x55555581bf81 main (gtest_main.cc:64)
  at 0x7ffff702a1c9 __libc_start_call_main (libc_start_call_main.h:58)
  at 0x7ffff702a28a __libc_start_main_impl (libc-start.c:360)
  at 0x555555586144 _start
Address 0x7fffffffbac0 is located in stack of thread T0 at offset 2400 in frame
  at 0x5555555b7905 ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)

@anonrig anonrig force-pushed the yagiz/maybe-asan-fix branch 3 times, most recently from 2af9bbf to 0116116 Compare December 30, 2024 01:33
@anonrig anonrig force-pushed the yagiz/maybe-asan-fix branch from 0116116 to 0fbe9ce Compare December 30, 2024 02:43
@lemire
Copy link
Member

lemire commented Dec 30, 2024

@anonrig

The C++ spec is clear...
https://en.cppreference.com/w/cpp/utility/expected/operator_bool

So both if(myresult) and if(myresult.has_value()) should be equivalent. Otherwise there is a bug in the implementation of std::expected.

@lemire
Copy link
Member

lemire commented Dec 30, 2024

@anonrig Here is how they are implemented:

image

So there is no difference between the two. It is the same function.

@anonrig
Copy link
Member Author

anonrig commented Dec 30, 2024

@lemire Yes, I think tl::expected<url_pattern_component... line is the real reason why this PR has a better stack trace.

@anonrig
Copy link
Member Author

anonrig commented Dec 30, 2024

@mikea
Copy link
Collaborator

mikea commented Dec 30, 2024

My instinct tells me to suspect one of these uninitialized booleans. This would be consistent with what you see.

image

@anonrig
Copy link
Member Author

anonrig commented Dec 30, 2024

My instinct tells me to suspect one of these uninitialized booleans. This would be consistent with what you see.

@mikea initializing all of them still gives the following error under -DADA_SANITIZE_UNDEFINED=ON

Load of value 6, which is not a valid value for type 'bool'
  at 0x5555555fffb3 tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::has_value() const
  at 0x5555556053ac ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)
  at 0x5555555ce8b6 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x5555557bfdde void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b76a8 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x55555578ff4d testing::Test::Run() (gtest.cc:2713)
  at 0x555555790a0b testing::TestInfo::Run() (gtest.cc:2859)
  at 0x5555557913d3 testing::TestSuite::Run() (gtest.cc:3037)
  at 0x5555557a13f9 testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:5967)
  at 0x5555557c133b bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2638)
  at 0x5555557b8a40 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2674)
  at 0x55555579f8e5 testing::UnitTest::Run() (gtest.cc:5546)
  at 0x55555577b899 RUN_ALL_TESTS() (gtest.h:2334)
  at 0x55555577b881 main (gtest_main.cc:64)
  at 0x7ffff702a1c9 __libc_start_call_main (libc_start_call_main.h:58)
  at 0x7ffff702a28a __libc_start_main_impl (libc-start.c:360)
  at 0x5555555cde24 _start

It gives the following failure under -DADA_SANITIZE_WITHOUT_LEAKS=ON

Stack-buffer-overflow on address 0x7fffffffba00 at pc 0x7ffff78fb303 bp 0x7fffffffa5d0 sp 0x7fffffff9d78
WRITE of size 2 at 0x7fffffffba00 thread T0
  at 0x7ffff78fb302 memcpy (sanitizer_common_interceptors_memintrinsics.inc:115)
  at 0x55555559fc18 std::char_traits<char>::copy(char*, char const*, unsigned long)
  at 0x5555555c0223 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) (basic_string.h:683)
  at 0x555555667979 ada::url_pattern_component::url_pattern_component(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool) (url_pattern.h:208)
  at 0x555555732c02 tl::detail::expected_storage_base<ada::url_pattern_component, ada::url_pattern_errors, false, true>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:616)
  at 0x5555557174de tl::detail::expected_operations_base<ada::url_pattern_component, ada::url_pattern_errors>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:727)
  at 0x555555717626 tl::detail::expected_copy_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:987)
  at 0x55555571776e tl::detail::expected_move_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1023)
  at 0x5555557178b6 tl::detail::expected_copy_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1058)
  at 0x5555557179fe tl::detail::expected_move_assign_base<ada::url_pattern_component, ada::url_pattern_errors, false>::expected_storage_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1098)
  at 0x555555717ae5 tl::expected<ada::url_pattern_component, ada::url_pattern_errors>::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool const&, (void*)0>(tl::in_place_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >&&, std::regex_constants::syntax_option_type&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&, bool const&) (expected.h:1608)
  at 0x5555556c7cc2 tl::expected<ada::url_pattern_component, ada::url_pattern_errors> ada::url_pattern_component::compile<tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >)>(std::basic_string_view<char, std::char_traits<char> >, tl::expected<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, ada::url_pattern_errors> (*)(std::basic_string_view<char, std::char_traits<char> >), ada::url_pattern_compile_component_options&) (url_pattern.cpp:542)
  at 0x5555555ba18b ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)
  at 0x5555555876f1 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x5555558608a0 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x55555585816a void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x555555830a0f testing::Test::Run() (gtest.cc:2713)
  at 0x5555558314cd testing::TestInfo::Run() (gtest.cc:2859)
  at 0x555555831e95 testing::TestSuite::Run() (gtest.cc:3037)
  at 0x555555841ebb testing::internal::UnitTestImpl::RunAllTests() (gtest.cc:5967)
  at 0x555555861dfd bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2638)
  at 0x555555859502 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (gtest.cc:2674)
  at 0x5555558403a7 testing::UnitTest::Run() (gtest.cc:5546)
  at 0x55555581c35b RUN_ALL_TESTS() (gtest.h:2334)
  at 0x55555581c343 main (gtest_main.cc:64)
  at 0x7ffff702a1c9 __libc_start_call_main (libc_start_call_main.h:58)
  at 0x7ffff702a28a __libc_start_main_impl (libc-start.c:360)
  at 0x555555586144 _start
Address 0x7fffffffba00 is located in stack of thread T0 at offset 2400 in frame
  at 0x5555555b7cc5 ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*)

@anonrig
Copy link
Member Author

anonrig commented Dec 30, 2024

Running under valgrind shows MismatchedAllocateDeallocateSize with the following stack trace (there are 5 different mismatch, but here's the first one)

Mismatched new/delete size value: 82061953
  at 0x484A5B9 operator delete(void*, unsigned long)
  at 0x140D18 std::__new_allocator<char>::deallocate(char*, unsigned long) (new_allocator.h:172)
  at 0x137D5D deallocate (allocator.h:210)
  at 0x137D5D deallocate (alloc_traits.h:517)
  at 0x137D5D std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_destroy(unsigned long) (basic_string.h:289)
  at 0x136DEF std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose() (basic_string.h:283)
  at 0x132713 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (basic_string.h:804)
  at 0x12E451 ada::url_pattern_component::~url_pattern_component() (url_pattern.h:195)
  at 0x12E687 ada::url_pattern::~url_pattern() (url_pattern.h:258)
  at 0x130BE4 ada::parse_url_pattern(std::variant<std::basic_string_view<char, std::char_traits<char> >, ada::url_pattern_init>, std::basic_string_view<char, std::char_traits<char> > const*, ada::url_pattern_options const*) (implementation-inl.h:262)
  at 0x11B3B4 wpt_urlpattern_tests_basic_tests_Test::TestBody() (wpt_urlpattern_tests.cpp:20)
  at 0x2B0AB2 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2638)
  at 0x2A837C void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (gtest.cc:2674)
  at 0x280C21 testing::Test::Run() (gtest.cc:2713)
Address 0x4e42a60 is 0 bytes inside a block of size 32 alloc'd
  at 0x4846FA3 operator new(unsigned long)
  at 0x20830F std::__new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned long, void const*) (new_allocator.h:151)
  at 0x1F571A allocate (allocator.h:198)
  at 0x1F571A allocate (alloc_traits.h:482)
  at 0x1F571A std::__cxx1998::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_allocate(unsigned long) (stl_vector.h:381)
  at 0x20D2AC std::__cxx1998::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_create_storage(unsigned long) (stl_vector.h:398)
  at 0x207148 std::__cxx1998::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_Vector_base(unsigned long, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) (stl_vector.h:335)
  at 0x2008D8 std::__cxx1998::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::vector(std::__cxx1998::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (stl_vector.h:603)
  at 0x1F9B76 std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::vector(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) (vector:212)
  at 0x1F9BE7 std::_Head_base<1ul, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, false>::_Head_base<std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) (tuple:201)
  at 0x1F2879 std::_Tuple_impl<1ul, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Tuple_impl<std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) (tuple:514)
  at 0x1E8E5F std::_Tuple_impl<0ul, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Tuple_impl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, void>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) (tuple:293)
  at 0x1DF3E5 std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, true>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) (tuple:1347)
  at 0x1718F0 ada::url_pattern_helpers::generate_regular_expression_and_name_list[abi:cxx11](std::__debug::vector<ada::url_pattern_part, std::allocator<ada::url_pattern_part> >&, ada::url_pattern_compile_component_options) (url_pattern.cpp:680)

@anonrig
Copy link
Member Author

anonrig commented Dec 31, 2024

@lemire this clears all valgrind + sanitizer leak errors:

diff --git a/include/ada/url_pattern-inl.h b/include/ada/url_pattern-inl.h
index c7c04a06..6da583e9 100644
--- a/include/ada/url_pattern-inl.h
+++ b/include/ada/url_pattern-inl.h
@@ -41,7 +41,7 @@ url_pattern_component::create_component_match_result(
     // Let value be Get(execResult, ToString(index)).
     // Set groups[name] to value.
     result.groups.insert({
-        group_name_list[index - 1],
+        "",
         exec_result[index].str(),
     });
   }
diff --git a/include/ada/url_pattern.h b/include/ada/url_pattern.h
index 13466dd6..7aa41a57 100644
--- a/include/ada/url_pattern.h
+++ b/include/ada/url_pattern.h
@@ -203,9 +203,8 @@ class url_pattern_component {
                         std::vector<std::string>&& new_group_name_list,
                         bool new_has_regexp_groups)
       : regexp(new_regexp),
-        pattern(std::move(new_pattern)),
+        pattern(new_pattern),
         flags(new_flags),
-        group_name_list(new_group_name_list),
         has_regexp_groups(new_has_regexp_groups) {}
 
   // @see https://urlpattern.spec.whatwg.org/#compile-a-component
@@ -223,7 +222,6 @@ class url_pattern_component {
   std::regex regexp{};
   std::string pattern{};
   std::regex_constants::syntax_option_type flags = std::regex::ECMAScript;
-  std::vector<std::string> group_name_list{};
   bool has_regexp_groups = false;
 };
 

@anonrig anonrig force-pushed the yagiz/add-url-pattern branch 3 times, most recently from 8292933 to 3aad757 Compare December 31, 2024 15:29
@anonrig anonrig closed this Dec 31, 2024
@anonrig
Copy link
Member Author

anonrig commented Jan 1, 2025

I've closed this pull-request but the original PR (#785) still has UBSAN failure on has_value() and/or bool operator of tl::expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants