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

seg fault with clang in get_topic() when publishing a message #534

Open
zontafil opened this issue Jan 30, 2025 · 0 comments
Open

seg fault with clang in get_topic() when publishing a message #534

zontafil opened this issue Jan 30, 2025 · 0 comments

Comments

@zontafil
Copy link

zontafil commented Jan 30, 2025

I'm trying something like this:

            std::string topic_test = "/test";
            std::string payload    = "test";
            std::stringstream sbuf2(payload);
            const mqtt::message_ptr msg = mqtt::make_message(topic_test, sbuf2.str());

            msg->set_qos(static_cast<int>(qos));

            // Publish the message
            mqtt_client_->publish(msg);

and I get a segfault


==931545==ERROR: AddressSanitizer: SEGV on unknown address 0x03e9000e36d9 (pc 0x7c57ac3bed2f bp 0x7c57a6dff940 sp 0x7c57a6dff940 T2)

5: ==931545==The signal is caused by a WRITE memory access.

5:     #0 0x7c57ac3bed2f in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider::_Alloc_hider(char*, std::allocator<char>&&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/basic_string.h:193
5:     #1 0x7c57ac3bed2f in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/basic_string.h:524
5:     #2 0x7c57ac3bed2f in mqtt::message::get_topic[abi:cxx11]() const /tmp/fsw-cmake/deps/Linux-x86_64-6.11.0-1012-oem-Ninja-Clang-19.1.7-lld/paho_mqtt_cpp-v1.5.0/paho_mqtt_cpp-src/include/mqtt/message.h:265
5:     #3 0x7c57ac3c196d in mqtt::delivery_token::delivery_token(mqtt::iasync_client&, std::shared_ptr<mqtt::message const>) /tmp/fsw-cmake/deps/Linux-x86_64-6.11.0-1012-oem-Ninja-Clang-19.1.7-lld/paho_mqtt_cpp-v1.5.0/paho_mqtt_cpp-src/include/mqtt/delivery_token.h:75
5:     #4 0x7c57ac3c196d in void std::_Construct<mqtt::delivery_token, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(mqtt::delivery_token*, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_construct.h:119
5:     #5 0x7c57ac3c196d in void std::allocator_traits<std::allocator<void> >::construct<mqtt::delivery_token, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(std::allocator<void>&, mqtt::delivery_token*, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/alloc_traits.h:661
5:     #6 0x7c57ac3c196d in std::_Sp_counted_ptr_inplace<mqtt::delivery_token, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(std::allocator<void>, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/shared_ptr_base.h:604
5:     #7 0x7c57ac3c18cc in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<mqtt::delivery_token, std::allocator<void>, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(mqtt::delivery_token*&, std::_Sp_alloc_shared_tag<std::allocator<void> >, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/shared_ptr_base.h:972
5:     #8 0x7c57ac3beb25 in std::__shared_ptr<mqtt::delivery_token, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/shared_ptr_base.h:1712
5:     #9 0x7c57ac3beb25 in std::shared_ptr<mqtt::delivery_token>::shared_ptr<std::allocator<void>, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(std::_Sp_alloc_shared_tag<std::allocator<void> >, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/shared_ptr.h:464
5:     #10 0x7c57ac3beb25 in std::shared_ptr<std::enable_if<!is_array<mqtt::delivery_token>::value, mqtt::delivery_token>::type> std::make_shared<mqtt::delivery_token, mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&>(mqtt::iasync_client&, std::shared_ptr<mqtt::message const>&) /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/shared_ptr.h:1009
5:     #11 0x7c57ac3beb25 in mqtt::delivery_token::create(mqtt::iasync_client&, std::shared_ptr<mqtt::message const>) /tmp/fsw-cmake/deps/Linux-x86_64-6.11.0-1012-oem-Ninja-Clang-19.1.7-lld/paho_mqtt_cpp-v1.5.0/paho_mqtt_cpp-src/include/mqtt/delivery_token.h:102
5:     #12 0x7c57ac3beb25 in mqtt::async_client::publish(std::shared_ptr<mqtt::message const>) /home/fzonta/Projects/fsw-workflow-manager/build//tmp/fsw-cmake/deps/Linux-x86_64-6.11.0-1012-oem-Ninja-Clang-19.1.7-lld/paho_mqtt_cpp-v1.5.0/paho_mqtt_cpp-src/src/async_client.cpp:596
5:     #13 0x7c57ac3ba57a in mqtt::client::publish(std::shared_ptr<mqtt::message const>) /tmp/fsw-cmake/deps/Linux-x86_64-6.11.0-1012-oem-Ninja-Clang-19.1.7-lld/paho_mqtt_cpp-v1.5.0/paho_mqtt_cpp-src/include/mqtt/client.h:296

the crash happens here:

    const string& get_topic() const {
        static const string EMPTY_STR; // <-- here
        return topic_ ? topic_.str() : EMPTY_STR;
    }

by replacing the static variable with a class variable, the segfault disappears. Note that I get this only with clang (version 19.1.7, linker LLD), and with some configurations only.

Do you have any suggestions?

I can try to create a more complete test that replicate the ctash if needed

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

No branches or pull requests

1 participant