summaryrefslogtreecommitdiffstats
path: root/debian/patches/CVE-2022-1897.patch
blob: e14fb4699f468c8e60047223a9f82ba402a31b9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From 338f1fc0ee3ca929387448fe464579d6113fa76a Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Thu, 26 May 2022 15:56:23 +0100
Subject: [PATCH] patch 8.2.5023: substitute overwrites allocated buffer

Problem:    Substitute overwrites allocated buffer.
Solution:   Disallow undo when in a substitute command.
---
 src/normal.c                    | 42 ++++++++++++++++-----------------
 src/testdir/test_substitute.vim | 22 +++++++++++++++++
 src/undo.c                      |  6 +++++
 src/version.c                   |  2 ++
 4 files changed, 51 insertions(+), 21 deletions(-)

--- a/src/normal.c
+++ b/src/normal.c
@@ -515,6 +515,22 @@ find_command(int cmdchar)
 }
 
 /*
+ * If currently editing a cmdline or text is locked: beep and give an error
+ * message, return TRUE.
+ */
+    static int
+check_text_locked(oparg_T *oap)
+{
+    if (text_locked())
+    {
+	clearopbeep(oap);
+	text_locked_msg();
+	return TRUE;
+    }
+    return FALSE;
+}
+
+/*
  * Execute a command in Normal mode.
  */
     void
@@ -775,14 +791,9 @@ getcount:
 	goto normal_end;
     }
 
-    if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW))
-    {
-	/* This command is not allowed while editing a cmdline: beep. */
-	clearopbeep(oap);
-	text_locked_msg();
-	goto normal_end;
-    }
-    if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked())
+    if ((nv_cmds[idx].cmd_flags & NV_NCW)
+				&& (check_text_locked(oap) || curbuf_locked()))
+	/* this command is not allowed now */
 	goto normal_end;
 
     /*
@@ -6162,12 +6173,8 @@ nv_gotofile(cmdarg_T *cap)
     char_u	*ptr;
     linenr_T	lnum = -1;
 
-    if (text_locked())
-    {
-	clearopbeep(cap->oap);
-	text_locked_msg();
+    if (check_text_locked(cap->oap))
 	return;
-    }
     if (curbuf_locked())
     {
 	clearop(cap->oap);
@@ -8328,14 +8335,7 @@ nv_g_cmd(cmdarg_T *cap)
 
     /* "gQ": improved Ex mode */
     case 'Q':
-	if (text_locked())
-	{
-	    clearopbeep(cap->oap);
-	    text_locked_msg();
-	    break;
-	}
-
-	if (!checkclearopq(oap))
+	if (!check_text_locked(cap->oap) && !checkclearopq(oap))
 	    do_exmode(TRUE);
 	break;
 
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -530,3 +530,25 @@ func Test_sub_change_window()
   delfunc Repl
 endfunc
 
+" This was undoign a change in between computing the length and using it.
+func Do_Test_sub_undo_change()
+  new
+  norm o0000000000000000000000000000000000000000000000000000
+  silent! s/\%')/\=Repl()
+  bwipe!
+endfunc
+
+func Test_sub_undo_change()
+  func Repl()
+    silent! norm g-
+  endfunc
+  call Do_Test_sub_undo_change()
+
+  func! Repl()
+    silent earlier
+  endfunc
+  call Do_Test_sub_undo_change()
+
+  delfunc Repl
+endfunc
+
--- a/src/undo.c
+++ b/src/undo.c
@@ -2278,6 +2278,12 @@ undo_time(
     int		    above = FALSE;
     int		    did_undo = TRUE;
 
+    if (text_locked())
+    {
+	text_locked_msg();
+	return;
+    }
+
     /* First make sure the current undoable change is synced. */
     if (curbuf->b_u_synced == FALSE)
 	u_sync(TRUE);
--- a/src/version.c
+++ b/src/version.c
@@ -796,6 +796,8 @@ static int included_patches[] =
 /**/
     5024,
 /**/
+    5023,
+/**/
     4977,
 /**/
     4921,