Patch 8.2.5043
Problem: Can open a cmdline window from a substitute expression.
Solution: Disallow opening a command line window when text or buffer is
locked.
Files: src/buffer.c, src/ex_getln.c, src/proto/
ex_getln.pro,
src/window.c, src/testdir/test_substitute.vim
*** ../vim-8.2.5042/src/buffer.c 2022-05-29 22:37:00.304418468 +0100
--- src/buffer.c 2022-05-30 14:38:08.913967768 +0100
***************
*** 2407,2418 ****
if (buf == curbuf)
return OK;
! if (text_locked())
! {
! text_locked_msg();
! return FAIL;
! }
! if (curbuf_locked())
return FAIL;
// altfpos may be changed by getfile(), get it now
--- 2407,2413 ----
if (buf == curbuf)
return OK;
! if (text_or_buf_locked())
return FAIL;
// altfpos may be changed by getfile(), get it now
*** ../vim-8.2.5042/src/ex_getln.c 2022-05-27 17:26:50.542119974 +0100
--- src/ex_getln.c 2022-05-30 15:22:06.316815749 +0100
***************
*** 2740,2745 ****
--- 2740,2760 ----
}
/*
+ * Check for text, window or buffer locked.
+ * Give an error message and return TRUE if something is locked.
+ */
+ int
+ text_or_buf_locked(void)
+ {
+ if (text_locked())
+ {
+ text_locked_msg();
+ return TRUE;
+ }
+ return curbuf_locked();
+ }
+
+ /*
* Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
* and give an error message.
*/
***************
*** 4379,4384 ****
--- 4394,4403 ----
int save_KeyTyped;
#endif
+ // Can't do this when text or buffer is locked.
+ if (text_or_buf_locked())
+ return K_IGNORE;
+
// Can't do this recursively. Can't do it when typing a password.
if (cmdwin_type != 0
# if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
*** ../vim-8.2.5042/src/proto/
ex_getln.pro 2022-05-27 17:26:50.542119974 +0100
--- src/proto/
ex_getln.pro 2022-05-30 14:38:51.553944527 +0100
***************
*** 3,11 ****
char_u *getcmdline(int firstc, long count, int indent, getline_opt_T do_concat);
char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg);
int check_opt_wim(void);
void text_locked_msg(void);
char *get_text_locked_msg(void);
! int text_locked(void);
int curbuf_locked(void);
int allbuf_locked(void);
char_u *getexline(int c, void *cookie, int indent, getline_opt_T options);
--- 3,12 ----
char_u *getcmdline(int firstc, long count, int indent, getline_opt_T do_concat);
char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg);
int check_opt_wim(void);
+ int text_locked(void);
void text_locked_msg(void);
char *get_text_locked_msg(void);
! int text_or_buf_locked(void);
int curbuf_locked(void);
int allbuf_locked(void);
char_u *getexline(int c, void *cookie, int indent, getline_opt_T options);
***************
*** 32,39 ****
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
void f_getcmdline(typval_T *argvars, typval_T *rettv);
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
- void f_setcmdpos(typval_T *argvars, typval_T *rettv);
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
int get_cmdline_firstc(void);
int get_list_range(char_u **str, int *num1, int *num2);
--- 33,40 ----
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
void f_getcmdline(typval_T *argvars, typval_T *rettv);
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
+ void f_setcmdpos(typval_T *argvars, typval_T *rettv);
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
int get_cmdline_firstc(void);
int get_list_range(char_u **str, int *num1, int *num2);
*** ../vim-8.2.5042/src/window.c 2022-05-28 10:49:39.946234986 +0100
--- src/window.c 2022-05-30 14:57:30.577199383 +0100
***************
*** 4585,4598 ****
return;
}
#endif
! if (text_locked())
{
beep_flush();
- text_locked_msg();
return;
}
- if (curbuf_locked())
- return;
if (wp->w_buffer != curbuf)
reset_VIsual_and_resel();
--- 4585,4595 ----
return;
}
#endif
! if (text_or_buf_locked())
{
beep_flush();
return;
}
if (wp->w_buffer != curbuf)
reset_VIsual_and_resel();
*** ../vim-8.2.5042/src/testdir/test_substitute.vim 2022-05-26 15:56:18.073351934 +0100
--- src/testdir/test_substitute.vim 2022-05-30 15:21:02.928853476 +0100
***************
*** 1035,1040 ****
--- 1035,1065 ----
delfunc Repl
endfunc
+ " This was opening a command line window from the expression
+ func Test_sub_open_cmdline_win()
+ " the error only happens in a very specific setup, run a new Vim instance to
+ " get a clean starting point.
+ let lines =<< trim [SCRIPT]
+ norm o0000000000000000000000000000000000000000000000000000
+ func Replace()
+ norm q/
+ endfunc
+ s/\%')/\=Replace()
+ redir >Xresult
+ messages
+ redir END
+ qall!
+ [SCRIPT]
+ call writefile(lines, 'Xscript')
+ if RunVim([], [], '-u NONE -S Xscript')
+ let messages = readfile('Xresult')
+ call assert_match('E565: Not allowed to change text or change window', messages[3])
+ endif
+
+ call delete('Xscript')
+ call delete('Xresult')
+ endfunc
+
" Test for the 2-letter and 3-letter :substitute commands
func Test_substitute_short_cmd()
new
*** ../vim-8.2.5042/src/version.c 2022-05-30 13:20:53.128825627 +0100
--- src/version.c 2022-05-30 14:38:07.189968693 +0100
***************
*** 736,737 ****
--- 736,739 ----
{ /* Add new patch number below this line */
+ /**/
+ 5043,
/**/
--
MORTICIAN: Bring out your dead!
[clang]
Bring out your dead!
[clang]
Bring out your dead!
CUSTOMER: Here's one -- nine pence.
DEAD PERSON: I'm not dead!
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///