-
-
Notifications
You must be signed in to change notification settings - Fork 123
Fix possible crash in History::erase() #160
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
Open
azat
wants to merge
1
commit into
AmokHuginnsson:master
Choose a base branch
from
azat-ch:fix-history-erase-upstream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The problem was that you can remove different entries from _locations
and _entries in case of Entry::_scratch does not match Entry::_text
(i.e. after some modifications of existing entries in history)
And you will get heap-use-after-free in this case:
=================================================================
==21751==ERROR: AddressSanitizer: heap-use-after-free on address 0x508000077be0 at pc 0x5555908ad5e9 bp 0x7fffffffa2c0 sp 0x7fffffffa2b8
READ of size 8 at 0x508000077be0 thread T0
#0 0x5555908ad5e8 in std::__1::vector<>::data[abi:ne190107]() const ci/tmp/build/./contrib/llvm-project/libcxx/include/vector:674:36
ClickHouse#1 0x5555908ad5e8 in replxx::UnicodeString::get() const ci/tmp/build/./contrib/replxx/src/unicodestring.hxx:148:16
ClickHouse#2 0x5555908ad5e8 in std::__1::hash<replxx::UnicodeString>::operator()(replxx::UnicodeString const&) const ci/tmp/build/./contrib/replxx/src/history.hxx:17:26
ClickHouse#3 0x5555908ad5e8 in ci/tmp/build/./contrib/llvm-project/libcxx/include/unordered_map:646:75
ClickHouse#4 0x5555908ad5e8 in ci/tmp/build/./contrib/llvm-project/libcxx/include/__hash_table:1748:20
ClickHouse#5 0x55559089c55b in ci/tmp/build/./contrib/llvm-project/libcxx/include/__hash_table:1851:18
ClickHouse#6 0x55559089c55b in ci/tmp/build/./contrib/llvm-project/libcxx/include/unordered_map:1322:80
ClickHouse#7 0x55559089c55b in replxx::History::erase(std::__1::__list_iterator<replxx::History::Entry, void*>) ci/tmp/build/./contrib/replxx/src/history.cxx:355:13
ClickHouse#8 0x55559089c55b in replxx::History::remove_duplicate(replxx::UnicodeString const&) ci/tmp/build/./contrib/replxx/src/history.cxx:381:2
ClickHouse#9 0x55559089b9ab in replxx::History::add(replxx::UnicodeString const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./contrib/replxx/src/history.cxx:94:2
ClickHouse#10 0x5555908e9d70 in replxx::Replxx::ReplxxImpl::history_add(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./contrib/replxx/src/replxx_impl.cxx:2467:11
ClickHouse#11 0x555586b4dc4f in DB::ReplxxLineReader::addToHistory(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./src/Client/ReplxxLineReader.cpp:527:8
ClickHouse#12 0x555586b11f7f in DB::LineReader::readLine(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./src/Client/LineReader.cpp:217:9
ClickHouse#13 0x555586a4445e in DB::ClientBase::runInteractive() ci/tmp/build/./src/Client/ClientBase.cpp:3335:25
0x508000077be0 is located 64 bytes inside of 88-byte region [0x508000077ba0,0x508000077bf8)
freed by thread T0 here:
#0 0x55556193a622 in operator delete(void*, unsigned long) (/src/ch/tmp/ci/clickhouse+0xc3e6622) (BuildId: 6b920302e2b03137aca21bee17dec6310aedbafa)
ClickHouse#1 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/new:274:3
ClickHouse#2 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/new:298:10
ClickHouse#3 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/new:311:12
ClickHouse#4 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/__memory/allocator.h:132:7
ClickHouse#5 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:312:9
ClickHouse#6 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/list:574:5
ClickHouse#7 0x55559089c60c in ci/tmp/build/./contrib/llvm-project/libcxx/include/list:1341:9
ClickHouse#8 0x55559089c60c in replxx::History::erase(std::__1::__list_iterator<replxx::History::Entry, void*>) ci/tmp/build/./contrib/replxx/src/history.cxx:356:17
ClickHouse#9 0x55559089c60c in replxx::History::remove_duplicate(replxx::UnicodeString const&) ci/tmp/build/./contrib/replxx/src/history.cxx:381:2
ClickHouse#10 0x55559089b9ab in replxx::History::add(replxx::UnicodeString const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./contrib/replxx/src/history.cxx:94:2
ClickHouse#11 0x5555908e9d70 in replxx::Replxx::ReplxxImpl::history_add(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./contrib/replxx/src/replxx_impl.cxx:2467:11
ClickHouse#12 0x555586b4dc4f in DB::ReplxxLineReader::addToHistory(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./src/Client/ReplxxLineReader.cpp:527:8
ClickHouse#13 0x555586b11f7f in DB::LineReader::readLine(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) ci/tmp/build/./src/Client/LineReader.cpp:217:9
ClickHouse#14 0x555586a4445e in DB::ClientBase::runInteractive() ci/tmp/build/./src/Client/ClientBase.cpp:3335:25
SUMMARY: AddressSanitizer: heap-use-after-free ci/tmp/build/./contrib/llvm-project/libcxx/include/vector:674:36 in std::__1::vector<char32_t, std::__1::allocator<char32_t>>::data[abi:ne190107]() const
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
May 24, 2025
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
May 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem was that you can remove different entries from _locations and _entries in case of Entry::_scratch does not match Entry::_text (i.e. after some modifications of existing entries in history)
And you will get heap-use-after-free in this case: