Patch 8.2.5023
Problem:    Substitute overwrites allocated buffer.
Solution:   Disallow undo when in a substitute command.
Files:      src/normal.c, src/undo.c, src/testdir/test_substitute.vim


*** ../vim-8.2.5022/src/normal.c        2022-05-14 21:29:40.665782815 +0100
--- src/normal.c        2022-05-26 15:49:31.757563967 +0100
***************
*** 184,189 ****
--- 184,205 ----
  }
  
  /*
+  * 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;
+ }
+ 
+ /*
   * Handle the count before a normal command and set cap->count0.
   */
      static int
***************
*** 802,815 ****
        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())
        goto normal_end;
  
      // In Visual/Select mode, a few keys are handled in a special way.
--- 818,826 ----
        goto normal_end;
      }
  
!     if ((nv_cmds[idx].cmd_flags & NV_NCW)
!                               && (check_text_locked(oap) || curbuf_locked()))
!       // this command is not allowed now
        goto normal_end;
  
      // In Visual/Select mode, a few keys are handled in a special way.
***************
*** 4049,4060 ****
      char_u    *ptr;
      linenr_T  lnum = -1;
  
!     if (text_locked())
!     {
!       clearopbeep(cap->oap);
!       text_locked_msg();
        return;
-     }
      if (curbuf_locked())
      {
        clearop(cap->oap);
--- 4060,4067 ----
      char_u    *ptr;
      linenr_T  lnum = -1;
  
!     if (check_text_locked(cap->oap))
        return;
      if (curbuf_locked())
      {
        clearop(cap->oap);
***************
*** 6182,6195 ****
  
      // "gQ": improved Ex mode
      case 'Q':
!       if (text_locked())
!       {
!           clearopbeep(cap->oap);
!           text_locked_msg();
!           break;
!       }
! 
!       if (!checkclearopq(oap))
            do_exmode(TRUE);
        break;
  
--- 6189,6195 ----
  
      // "gQ": improved Ex mode
      case 'Q':
!       if (!check_text_locked(cap->oap) && !checkclearopq(oap))
            do_exmode(TRUE);
        break;
  
*** ../vim-8.2.5022/src/undo.c  2022-05-12 15:39:27.815703293 +0100
--- src/undo.c  2022-05-26 15:51:18.505502159 +0100
***************
*** 2327,2332 ****
--- 2327,2338 ----
      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);
*** ../vim-8.2.5022/src/testdir/test_substitute.vim     2022-05-18 
13:11:53.159464114 +0100
--- src/testdir/test_substitute.vim     2022-05-26 15:54:01.425405292 +0100
***************
*** 1013,1018 ****
--- 1013,1040 ----
    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
+ 
  " Test for the 2-letter and 3-letter :substitute commands
  func Test_substitute_short_cmd()
    new
*** ../vim-8.2.5022/src/version.c       2022-05-26 15:23:22.917780369 +0100
--- src/version.c       2022-05-26 15:45:32.553695614 +0100
***************
*** 736,737 ****
--- 736,739 ----
  {   /* Add new patch number below this line */
+ /**/
+     5023,
  /**/

-- 
Yah, well, we had to carve our electrons out of driftwood we'd
find.  In the winter.  Uphill.  Both ways.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220526145654.3BD3E1C0B4C%40moolenaar.net.

Raspunde prin e-mail lui