Fix a buffer overflow in cached_esc_sequences_t::find_entry

cached_esc_sequences_t::find_entry was constructing a wcstring
from a c string, using lengths longer than the length of the cstring.

Detected with asan.
This commit is contained in:
ridiculousfish 2017-03-26 12:48:36 -07:00
parent 3d6c4adda9
commit 9f13edbe4a

View file

@ -242,7 +242,9 @@ class cached_esc_sequences_t {
} }
size_t find_entry(const wchar_t *entry) { size_t find_entry(const wchar_t *entry) {
size_t entry_len = wcslen(entry);
for (auto len : lengths) { for (auto len : lengths) {
if (len > entry_len) continue;
auto match = cache.find(wcstring(entry, len)); auto match = cache.find(wcstring(entry, len));
if (match != cache.end()) { // we found a matching cached sequence if (match != cache.end()) { // we found a matching cached sequence
// Periodically sort the sequence lengths so we check for matches going from the // Periodically sort the sequence lengths so we check for matches going from the