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

Manage when destructor is called for native webAPI #5807

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

esev
Copy link
Contributor

@esev esev commented Jan 10, 2025

This is intended to avoid a Static Initialization (Destruction) Order Fiasco issue that happens at shutdown. I believe the settingsMap is currently being destroyed before the webAPI. A log message in PhoneAPI::close() depends on settingsMap[logoutputlevel]

==16==ERROR: AddressSanitizer: heap-use-after-free on address 0x50400000212c at pc 0x556140daede5 bp 0x7fffbce7e5e0 sp 0x7fffbce7e5d8
READ of size 4 at 0x50400000212c thread T0
SCARINESS: 45 (4-byte-read-heap-use-after-free)
    #0 0x556140daede4 in std::__1::less<configNames>::operator()[abi:ne180100](configNames const&, configNames const&) const /usr/local/bin/../include/c++/v1/__functional
/operations.h:358:18
    #1 0x556140daeb0c in std::__1::__map_value_compare<configNames, std::__1::__value_type<configNames, int>, std::__1::less<configNames>, true>::operator()[abi:ne180100]
(configNames const&, std::__1::__value_type<configNames, int> const&) const /usr/local/bin/../include/c++/v1/map:643:12
    #2 0x556140daf626 in std::__1::__tree_node_base<void*>*& std::__1::__tree<std::__1::__value_type<configNames, int>, std::__1::__map_value_compare<configNames, std::__
1::__value_type<configNames, int>, std::__1::less<configNames>, true>, std::__1::allocator<std::__1::__value_type<configNames, int>>>::__find_equal<configNames>(std::__1:
:__tree_end_node<std::__1::__tree_node_base<void*>*>*&, configNames const&) /usr/local/bin/../include/c++/v1/__tree:1687:11
    #3 0x556140daf0e5 in std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<configNames, int>, std::__1::__tree_node<std::__1::__value_type<configNames, int>
, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<configNames, int>, std::__1::__map_value_compare<configNames, std::__1::__value_type<configNames, int>, std::__1::less<configNames>, true>, std::__1::allocator<std::__1::__value_type<configNames, int>>>::__emplace_unique_key_args<configNames, std::__1::piecewise_construct_t const&, std::__1::tuple<configNames&&>, std::__1::tuple<>>(configNames const&, std::__1::piecewise_construct_t const&, std::__1::tuple<configNames&&>&&, std::__1::tuple<>&&) /usr/local/bin/../include/c++/v1/__tree:1782:34
    #4 0x556140d9c4ff in std::__1::map<configNames, int, std::__1::less<configNames>, std::__1::allocator<std::__1::pair<configNames const, int>>>::operator[](configNames&&) /usr/local/bin/../include/c++/v1/map:1529:8
    #5 0x556140de28b1 in RedirectablePrint::log(char const*, char const*, ...) /src/firmware/src/RedirectablePrint.cpp:305:9
    #6 0x556140f7648f in PhoneAPI::close() /src/firmware/src/mesh/PhoneAPI.cpp:70:5
    #7 0x556140f75bbe in PhoneAPI::~PhoneAPI() /src/firmware/src/mesh/PhoneAPI.cpp:41:5
    #8 0x556140fd80b4 in HttpAPI::~HttpAPI() /src/firmware/src/mesh/raspihttp/PiWebServer.h:44:7
    #9 0x7f99cc9c78a6  (/out/lib/libc.so.6+0x468a6) (BuildId: 0702430aef5fa3dda43986563e9ffcc47efbd75e)
    #10 0x7f99cc9c7a5f in exit (/out/lib/libc.so.6+0x46a5f) (BuildId: 0702430aef5fa3dda43986563e9ffcc47efbd75e)
    #11 0x556140ad1e88 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp
    #12 0x556140afd202 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #13 0x7f99cc9a5082 in __libc_start_main (/out/lib/libc.so.6+0x24082) (BuildId: 0702430aef5fa3dda43986563e9ffcc47efbd75e)
    #14 0x556140ac46ad in _start (/out/router_fuzzer+0x2616ad)

I've also included a few changes to PiWebServerThread::~PiWebServerThread() to clean-up variables, and removed a seemingly unused instanceService member from that class.

Still to-do:

  • [x] Test the handleAPIv1FromRadio & handleAPIv1ToRadio handler changes locally

Tested locally using https://github.com/meshtastic/web/releases/download/v2.5.4/build.tar

@thebentern thebentern merged commit e7802d9 into meshtastic:master Jan 11, 2025
51 checks passed
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.

2 participants