Blame SOURCES/0001-patch-8.2.3487-illegal-memory-access-if-buffer-name-.patch

da4393
From 826bfe4bbd7594188e3d74d2539d9707b1c6a14b Mon Sep 17 00:00:00 2001
da4393
From: Bram Moolenaar <Bram@vim.org>
da4393
Date: Fri, 8 Oct 2021 18:39:28 +0100
da4393
Subject: [PATCH] patch 8.2.3487: illegal memory access if buffer name is very
da4393
 long
da4393
da4393
Problem:    Illegal memory access if buffer name is very long.
da4393
Solution:   Make sure not to go over the end of the buffer.
da4393
---
da4393
 src/drawscreen.c                | 10 +++++-----
da4393
 src/testdir/test_statusline.vim | 10 ++++++++++
da4393
 src/version.c                   |  2 ++
da4393
 3 files changed, 17 insertions(+), 5 deletions(-)
da4393
da4393
diff --git a/src/drawscreen.c b/src/drawscreen.c
da4393
index 82e53753b..e38ca9586 100644
da4393
--- a/src/drawscreen.c
da4393
+++ b/src/drawscreen.c
da4393
@@ -464,13 +464,13 @@ win_redr_status(win_T *wp, int ignore_pum UNUSED)
da4393
 	    *(p + len++) = ' ';
da4393
 	if (bt_help(wp->w_buffer))
da4393
 	{
da4393
-	    STRCPY(p + len, _("[Help]"));
da4393
+	    vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Help]"));
da4393
 	    len += (int)STRLEN(p + len);
da4393
 	}
da4393
 #ifdef FEAT_QUICKFIX
da4393
 	if (wp->w_p_pvw)
da4393
 	{
da4393
-	    STRCPY(p + len, _("[Preview]"));
da4393
+	    vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Preview]"));
da4393
 	    len += (int)STRLEN(p + len);
da4393
 	}
da4393
 #endif
da4393
@@ -480,12 +480,12 @@ win_redr_status(win_T *wp, int ignore_pum UNUSED)
da4393
 #endif
da4393
 		)
da4393
 	{
da4393
-	    STRCPY(p + len, "[+]");
da4393
-	    len += 3;
da4393
+	    vim_snprintf((char *)p + len, MAXPATHL - len, "%s", "[+]");
da4393
+	    len += (int)STRLEN(p + len);
da4393
 	}
da4393
 	if (wp->w_buffer->b_p_ro)
da4393
 	{
da4393
-	    STRCPY(p + len, _("[RO]"));
da4393
+	    vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[RO]"));
da4393
 	    len += (int)STRLEN(p + len);
da4393
 	}
da4393
 
da4393
diff --git a/src/testdir/test_statusline.vim b/src/testdir/test_statusline.vim
da4393
index f3eea2e71..a952de69b 100644
da4393
--- a/src/testdir/test_statusline.vim
da4393
+++ b/src/testdir/test_statusline.vim
da4393
@@ -522,4 +522,14 @@ func Test_statusline_mbyte_fillchar()
da4393
   %bw!
da4393
 endfunc
da4393
 
da4393
+" Used to write beyond allocated memory.  This assumes MAXPATHL is 4096 bytes.
da4393
+func Test_statusline_verylong_filename()
da4393
+  let fname = repeat('x', 4090)
da4393
+  exe "new " .. fname
da4393
+  set buftype=help
da4393
+  set previewwindow
da4393
+  redraw
da4393
+  bwipe!
da4393
+endfunc
da4393
+
da4393
 " vim: shiftwidth=2 sts=2 expandtab
da4393
-- 
da4393
2.31.1
da4393