Solc LSP crashes due to NULL Pointer Dereference under specific message sequence.
Description
Using fuzzing, I found 3 crashes in Solc LSP. They share different ASAN logs.
Environment
-
Compiler version: 0.8.29 (ASAN build) and 0.8.34+commit.80d5c536.Linux.g++(Non ASAN built)
-
Compilation pipeline: LSP
-
Target EVM version: N/A
-
Framework/IDE: LSP client (fuzzing harness)
-
Backend: N/A
-
Operating system: Ubuntu 24.04
Steps to Reproduce
They are affiliated in the package below. Run the python script and hopefully, it will trigger the crash, even if you don't use the ASANed one. Run it like this:
python3 repro.py /path/to/solc
solc_latest_triggered_only_with_asanlogs.zip
Full ASAN log
/tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:68:28: runtime error: reference binding to null pointer of type 'const ASTNode'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:68:28
=================================================================
==11980==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5ec04273a911 bp 0x7ffe230a3db0 sp 0x7ffe230a3ce0 T0)
==11980==The signal is caused by a READ memory access.
==11980==Hint: address points to the zero page.
#0 0x5ec04273a911 in solidity::lsp::RenameSymbol::extractNameAndDeclaration(solidity::frontend::ASTNode const&, int) /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:127:32
#1 0x5ec0427381b9 in solidity::lsp::RenameSymbol::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:68:2
#2 0x5ec041c5f9ca in void std::__invoke_impl<void, solidity::lsp::RenameSymbol&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&>(std::__invoke_other, solidity::lsp::RenameSymbol&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>&&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:61:14
#3 0x5ec041c58b3b in std::function<void (nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&)>::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) const /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_function.h:591:9
#4 0x5ec041c58b3b in solidity::lsp::LanguageServer::run() /tmp/solidity-0.8.29/libsolidity/lsp/LanguageServer.cpp:351:6
#5 0x5ec0417ef30c in solidity::frontend::CommandLineInterface::serveLSP() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:1183:38
#6 0x5ec0417ee5d9 in solidity::frontend::CommandLineInterface::processInput() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:848:3
#7 0x5ec0417ecf95 in solidity::frontend::CommandLineInterface::run(int, char const* const*) /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:766:3
#8 0x5ec0417ba1cd in main /tmp/solidity-0.8.29/solc/main.cpp:40:14
#9 0x7c734562a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#10 0x7c734562a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#11 0x5ec0416de4b4 in _start (/home/ubuntu2404/lsp_assets/lsp_server/solc_asan+0x105b4b4) (BuildId: 25de741a1bd233bbe408841fca25239fd484a9a8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:127:32 in solidity::lsp::RenameSymbol::extractNameAndDeclaration(solidity::frontend::ASTNode const&, int)
==11980==ABORTING
/tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:159:2: runtime error: member call on null pointer of type 'solidity::frontend::Declaration'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:159:2
=================================================================
==11232==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5572d5f19334 bp 0x7ffd15893f10 sp 0x7ffd15893e40 T0)
==11232==The signal is caused by a READ memory access.
==11232==Hint: address points to the zero page.
#0 0x5572d5f19334 in solidity::frontend::Declaration::nameLocation() const /tmp/solidity-0.8.29/libsolidity/ast/AST.h:270:63
#1 0x5572d5f19334 in solidity::lsp::RenameSymbol::extractNameAndDeclaration(solidity::frontend::ASTNode const&, int) /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:159:2
#2 0x5572d5f161b9 in solidity::lsp::RenameSymbol::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /tmp/solidity-0.8.29/libsolidity/lsp/RenameSymbol.cpp:68:2
#3 0x5572d543d9ca in void std::__invoke_impl<void, solidity::lsp::RenameSymbol&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&>(std::__invoke_other, solidity::lsp::RenameSymbol&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>&&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:61:14
#4 0x5572d5436b3b in std::function<void (nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&)>::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) const /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_function.h:591:9
#5 0x5572d5436b3b in solidity::lsp::LanguageServer::run() /tmp/solidity-0.8.29/libsolidity/lsp/LanguageServer.cpp:351:6
#6 0x5572d4fcd30c in solidity::frontend::CommandLineInterface::serveLSP() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:1183:38
#7 0x5572d4fcc5d9 in solidity::frontend::CommandLineInterface::processInput() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:848:3
#8 0x5572d4fcaf95 in solidity::frontend::CommandLineInterface::run(int, char const* const*) /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:766:3
#9 0x5572d4f981cd in main /tmp/solidity-0.8.29/solc/main.cpp:40:14
#10 0x77cefe22a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#11 0x77cefe22a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#12 0x5572d4ebc4b4 in _start (/home/ubuntu2404/lsp_assets/lsp_server/solc_asan+0x105b4b4) (BuildId: 25de741a1bd233bbe408841fca25239fd484a9a8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /tmp/solidity-0.8.29/libsolidity/ast/AST.h:270:63 in solidity::frontend::Declaration::nameLocation() const
==11232==ABORTING
==================================================
/tmp/solidity-0.8.29/libsolidity/lsp/DocumentHoverHandler.cpp:92:52: runtime error: member call on null pointer of type 'solidity::frontend::StructuredDocumentation'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /tmp/solidity-0.8.29/libsolidity/lsp/DocumentHoverHandler.cpp:92:52
=================================================================
==14572==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x63b5162a9cd9 bp 0x7ffcb0c5aa70 sp 0x7ffcb0c5aa60 T0)
==14572==The signal is caused by a READ memory access.
==14572==Hint: address points to the zero page.
#0 0x63b5162a9cd9 in solidity::frontend::StructuredDocumentation::text[abi:cxx11]() const /tmp/solidity-0.8.29/libsolidity/ast/AST.h:436:53
#1 0x63b5162a8d2a in solidity::lsp::DocumentHoverHandler::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /tmp/solidity-0.8.29/libsolidity/lsp/DocumentHoverHandler.cpp:92:52
#2 0x63b5157da2aa in void std::__invoke_impl<void, solidity::lsp::DocumentHoverHandler&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&>(std::__invoke_other, solidity::lsp::DocumentHoverHandler&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>&&, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:61:14
#3 0x63b5157d3b3b in std::function<void (nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&)>::operator()(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void> const&) const /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_function.h:591:9
#4 0x63b5157d3b3b in solidity::lsp::LanguageServer::run() /tmp/solidity-0.8.29/libsolidity/lsp/LanguageServer.cpp:351:6
#5 0x63b51536a30c in solidity::frontend::CommandLineInterface::serveLSP() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:1183:38
#6 0x63b5153695d9 in solidity::frontend::CommandLineInterface::processInput() /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:848:3
#7 0x63b515367f95 in solidity::frontend::CommandLineInterface::run(int, char const* const*) /tmp/solidity-0.8.29/solc/CommandLineInterface.cpp:766:3
#8 0x63b5153351cd in main /tmp/solidity-0.8.29/solc/main.cpp:40:14
#9 0x750b21c2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#10 0x750b21c2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#11 0x63b5152594b4 in _start (/home/ubuntu2404/lsp_assets/lsp_server/solc_asan+0x105b4b4) (BuildId: 25de741a1bd233bbe408841fca25239fd484a9a8)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /tmp/solidity-0.8.29/libsolidity/ast/AST.h:436:53 in solidity::frontend::StructuredDocumentation::text[abi:cxx11]() const
==14572==ABORTING
Hi, thank you for fuzzing and your reports! We will soon remove LSP from the codebase, it's never been fully stabilized and development pretty much stopped. See https://github.com/argotorg/solidity/issues/16124
So I'm closing this.