Blame SOURCES/0001-patch-8.2.4218-illegal-memory-access-with-bracketed-.patch

da4393
From 806d037671e133bd28a7864248763f643967973a Mon Sep 17 00:00:00 2001
da4393
From: Bram Moolenaar <Bram@vim.org>
da4393
Date: Tue, 25 Jan 2022 20:45:16 +0000
da4393
Subject: [PATCH] patch 8.2.4218: illegal memory access with bracketed paste in
da4393
 Ex mode
da4393
da4393
Problem:    Illegal memory access with bracketed paste in Ex mode.
da4393
Solution:   Reserve space for the trailing NUL.
da4393
---
da4393
 src/edit.c                 | 3 ++-
da4393
 src/testdir/test_paste.vim | 3 +++
da4393
 src/version.c              | 2 ++
da4393
 3 files changed, 7 insertions(+), 1 deletion(-)
da4393
da4393
diff --git a/src/edit.c b/src/edit.c
da4393
index ee3caf0da..2b5301100 100644
da4393
--- a/src/edit.c
da4393
+++ b/src/edit.c
da4393
@@ -4452,7 +4452,8 @@ bracketed_paste(paste_mode_T mode, int drop, garray_T *gap)
da4393
 		    break;
da4393
 
da4393
 		case PASTE_EX:
da4393
-		    if (gap != NULL && ga_grow(gap, idx) == OK)
da4393
+		    // add one for the NUL that is going to be appended
da4393
+		    if (gap != NULL && ga_grow(gap, idx + 1) == OK)
da4393
 		    {
da4393
 			mch_memmove((char *)gap->ga_data + gap->ga_len,
da4393
 							     buf, (size_t)idx);
da4393
diff --git a/src/testdir/test_paste.vim b/src/testdir/test_paste.vim
da4393
index c94fe7c35..5b8d8a0e3 100644
da4393
--- a/src/testdir/test_paste.vim
da4393
+++ b/src/testdir/test_paste.vim
da4393
@@ -90,6 +90,9 @@ func Test_paste_ex_mode()
da4393
   unlet! foo
da4393
   call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt')
da4393
   call assert_equal("foo\rbar", foo)
da4393
+
da4393
+  " pasting more than 40 bytes
da4393
+  exe "norm Q\<PasteStart>0000000000000000000000000000000000000000000000000000000000000000000000\<C-C>"
da4393
 endfunc
da4393
 
da4393
 func Test_paste_onechar()
da4393
-- 
da4393
2.34.1
da4393