Skip to content

Commit e6c2374

Browse files
committed
Fix use-after-free when diffing buffer in pipe
The string view being held into the buffer may get invalidated by the buffer operations being applied, ensure the buffer lines are kept alive by acquiring a refptr to them.
1 parent 1ac81b2 commit e6c2374

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/normal.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,13 @@ void pipe(Context& context, NormalParams params)
688688
const auto first = changes_tracker.get_new_coord_tolerant(sel.min());
689689
const auto last = changes_tracker.get_new_coord_tolerant(sel.max());
690690

691+
Vector<StringDataPtr> keep_alive;
691692
Vector<StringView> in_lines;
692693
for (auto line = first.line; line <= last.line; ++line)
693694
{
694-
auto content = buffer[line];
695+
auto& storage = buffer.line_storage(line);
696+
keep_alive.push_back(storage);
697+
auto content = storage->strview();;
695698
if (line == last.line)
696699
content = content.substr(0, last.column + utf8::codepoint_size(content[last.column]));
697700
if (line == first.line)

0 commit comments

Comments
 (0)