Blame SOURCES/7.4.565

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.565
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.565
22c937
Problem:    Ranges for arguments, buffers, tabs, etc. are not checked to be
22c937
	    valid but limited to the maximum.  This can cause the wrong thing
22c937
	    to happen.
22c937
Solution:   Give an error for an invalid value. (Marcin Szamotulski)
22c937
	    Use windows range for ":wincmd".
22c937
Files:	    src/ex_docmd.c, src/ex_cmds.h, src/testdir/test62.in,
22c937
	    src/testdir/test_argument_count.in,
22c937
	    src/testdir/test_argument_count.ok,
22c937
	    src/testdir/test_close_count.in,
22c937
	    src/testdir/test_command_count.in,
22c937
	    src/testdir/test_command_count.ok
22c937
22c937
22c937
*** ../vim-7.4.564/src/ex_docmd.c	2015-01-07 13:15:40.605829542 +0100
22c937
--- src/ex_docmd.c	2015-01-07 15:33:21.950217606 +0100
22c937
***************
22c937
*** 2161,2166 ****
22c937
--- 2161,2168 ----
22c937
  		break;
22c937
  	    case ADDR_ARGUMENTS:
22c937
  		ea.line2 = curwin->w_arg_idx + 1;
22c937
+ 		if (ea.line2 > ARGCOUNT)
22c937
+ 		    ea.line2 = ARGCOUNT;
22c937
  		break;
22c937
  	    case ADDR_LOADED_BUFFERS:
22c937
  	    case ADDR_BUFFERS:
22c937
***************
22c937
*** 3110,3116 ****
22c937
       * Exceptions:
22c937
       * - the 'k' command can directly be followed by any character.
22c937
       * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
22c937
!      *	    but :sre[wind] is another command, as are :scrip[tnames],
22c937
       *	    :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
22c937
       * - the "d" command can directly be followed by 'l' or 'p' flag.
22c937
       */
22c937
--- 3112,3118 ----
22c937
       * Exceptions:
22c937
       * - the 'k' command can directly be followed by any character.
22c937
       * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
22c937
!      *	    but :sre[wind] is another command, as are :scr[iptnames],
22c937
       *	    :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
22c937
       * - the "d" command can directly be followed by 'l' or 'p' flag.
22c937
       */
22c937
***************
22c937
*** 4573,4618 ****
22c937
  		lnum -= n;
22c937
  	    else
22c937
  		lnum += n;
22c937
- 
22c937
- 	    switch (addr_type)
22c937
- 	    {
22c937
- 		case ADDR_LINES:
22c937
- 		    break;
22c937
- 		case ADDR_ARGUMENTS:
22c937
- 		    if (lnum < 0)
22c937
- 			lnum = 0;
22c937
- 		    else if (lnum >= ARGCOUNT)
22c937
- 			lnum = ARGCOUNT;
22c937
- 		    break;
22c937
- 		case ADDR_TABS:
22c937
- 		    if (lnum < 0)
22c937
- 		    {
22c937
- 			lnum = 0;
22c937
- 			break;
22c937
- 		    }
22c937
- 		    if (lnum >= LAST_TAB_NR)
22c937
- 			lnum = LAST_TAB_NR;
22c937
- 		    break;
22c937
- 		case ADDR_WINDOWS:
22c937
- 		    if (lnum < 0)
22c937
- 		    {
22c937
- 			lnum = 0;
22c937
- 			break;
22c937
- 		    }
22c937
- 		    if (lnum >= LAST_WIN_NR)
22c937
- 			lnum = LAST_WIN_NR;
22c937
- 		    break;
22c937
- 		case ADDR_LOADED_BUFFERS:
22c937
- 		case ADDR_BUFFERS:
22c937
- 		    if (lnum < firstbuf->b_fnum)
22c937
- 		    {
22c937
- 			lnum = firstbuf->b_fnum;
22c937
- 			break;
22c937
- 		    }
22c937
- 		    if (lnum > lastbuf->b_fnum)
22c937
- 			lnum = lastbuf->b_fnum;
22c937
- 		    break;
22c937
- 	    }
22c937
  	}
22c937
      } while (*cmd == '/' || *cmd == '?');
22c937
  
22c937
--- 4575,4580 ----
22c937
***************
22c937
*** 4675,4691 ****
22c937
  invalid_range(eap)
22c937
      exarg_T	*eap;
22c937
  {
22c937
      if (       eap->line1 < 0
22c937
  	    || eap->line2 < 0
22c937
! 	    || eap->line1 > eap->line2
22c937
! 	    || ((eap->argt & RANGE)
22c937
! 		&& !(eap->argt & NOTADR)
22c937
! 		&& eap->line2 > curbuf->b_ml.ml_line_count
22c937
  #ifdef FEAT_DIFF
22c937
! 			+ (eap->cmdidx == CMD_diffget)
22c937
  #endif
22c937
! 		))
22c937
! 	return (char_u *)_(e_invrange);
22c937
      return NULL;
22c937
  }
22c937
  
22c937
--- 4637,4701 ----
22c937
  invalid_range(eap)
22c937
      exarg_T	*eap;
22c937
  {
22c937
+     buf_T	*buf;
22c937
      if (       eap->line1 < 0
22c937
  	    || eap->line2 < 0
22c937
! 	    || eap->line1 > eap->line2)
22c937
! 	return (char_u *)_(e_invrange);
22c937
! 
22c937
!     if (eap->argt & RANGE)
22c937
!     {
22c937
! 	switch(eap->addr_type)
22c937
! 	{
22c937
! 	    case ADDR_LINES:
22c937
! 		if (!(eap->argt & NOTADR)
22c937
! 			&& eap->line2 > curbuf->b_ml.ml_line_count
22c937
  #ifdef FEAT_DIFF
22c937
! 			    + (eap->cmdidx == CMD_diffget)
22c937
  #endif
22c937
! 		   )
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	    case ADDR_ARGUMENTS:
22c937
! 		if (eap->line2 > ARGCOUNT + (!ARGCOUNT))    // add 1 if ARCOUNT is 0
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	    case ADDR_BUFFERS:
22c937
! 		if (eap->line1 < firstbuf->b_fnum
22c937
! 			|| eap->line2 > lastbuf->b_fnum)
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	    case ADDR_LOADED_BUFFERS:
22c937
! 		buf = firstbuf;
22c937
! 		while (buf->b_ml.ml_mfp == NULL)
22c937
! 		{
22c937
! 		    if (buf->b_next == NULL)
22c937
! 			return (char_u *)_(e_invrange);
22c937
! 		    buf = buf->b_next;
22c937
! 		}
22c937
! 		if (eap->line1 < buf->b_fnum)
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		buf = lastbuf;
22c937
! 		while (buf->b_ml.ml_mfp == NULL)
22c937
! 		{
22c937
! 		    if (buf->b_prev == NULL)
22c937
! 			return (char_u *)_(e_invrange);
22c937
! 		    buf = buf->b_prev;
22c937
! 		}
22c937
! 		if (eap->line2 > buf->b_fnum)
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	    case ADDR_WINDOWS:
22c937
! 		if (eap->line1 < 1
22c937
! 			|| eap->line2 > LAST_WIN_NR)
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	    case ADDR_TABS:
22c937
! 		if (eap->line2 > LAST_TAB_NR)
22c937
! 		    return (char_u *)_(e_invrange);
22c937
! 		break;
22c937
! 	}
22c937
!     }
22c937
      return NULL;
22c937
  }
22c937
  
22c937
*** ../vim-7.4.564/src/ex_cmds.h	2014-12-17 14:36:10.363090985 +0100
22c937
--- src/ex_cmds.h	2015-01-07 15:47:15.336518550 +0100
22c937
***************
22c937
*** 1574,1580 ****
22c937
  			ADDR_LINES),
22c937
  EX(CMD_wincmd,		"wincmd",	ex_wincmd,
22c937
  			NEEDARG|WORD1|RANGE|NOTADR,
22c937
! 			ADDR_LINES),
22c937
  EX(CMD_windo,		"windo",	ex_listdo,
22c937
  			BANG|NEEDARG|EXTRA|NOTRLCOM,
22c937
  			ADDR_LINES),
22c937
--- 1574,1580 ----
22c937
  			ADDR_LINES),
22c937
  EX(CMD_wincmd,		"wincmd",	ex_wincmd,
22c937
  			NEEDARG|WORD1|RANGE|NOTADR,
22c937
! 			ADDR_WINDOWS),
22c937
  EX(CMD_windo,		"windo",	ex_listdo,
22c937
  			BANG|NEEDARG|EXTRA|NOTRLCOM,
22c937
  			ADDR_LINES),
22c937
*** ../vim-7.4.564/src/testdir/test62.in	2014-04-29 11:55:26.172053624 +0200
22c937
--- src/testdir/test62.in	2015-01-07 15:33:21.950217606 +0100
22c937
***************
22c937
*** 13,19 ****
22c937
  :" Open three tab pages and use ":tabdo"
22c937
  :0tabnew
22c937
  :1tabnew
22c937
! :888tabnew
22c937
  :tabdo call append(line('$'), 'this is tab page ' . tabpagenr())
22c937
  :tabclose! 2
22c937
  :tabrewind
22c937
--- 13,19 ----
22c937
  :" Open three tab pages and use ":tabdo"
22c937
  :0tabnew
22c937
  :1tabnew
22c937
! :$tabnew
22c937
  :tabdo call append(line('$'), 'this is tab page ' . tabpagenr())
22c937
  :tabclose! 2
22c937
  :tabrewind
22c937
*** ../vim-7.4.564/src/testdir/test_argument_count.in	2014-11-27 18:32:58.532564506 +0100
22c937
--- src/testdir/test_argument_count.in	2015-01-07 15:33:21.950217606 +0100
22c937
***************
22c937
*** 27,36 ****
22c937
  :1arga c
22c937
  :1arga b
22c937
  :$argu
22c937
- :+arga d
22c937
  :$arga x
22c937
  :call add(arglists, argv())
22c937
! :$-10arga Y
22c937
  :call add(arglists, argv())
22c937
  :%argd
22c937
  :call add(arglists, argv())
22c937
--- 27,35 ----
22c937
  :1arga c
22c937
  :1arga b
22c937
  :$argu
22c937
  :$arga x
22c937
  :call add(arglists, argv())
22c937
! :0arga Y
22c937
  :call add(arglists, argv())
22c937
  :%argd
22c937
  :call add(arglists, argv())
22c937
*** ../vim-7.4.564/src/testdir/test_argument_count.ok	2014-11-27 16:22:42.746412995 +0100
22c937
--- src/testdir/test_argument_count.ok	2015-01-07 15:33:21.950217606 +0100
22c937
***************
22c937
*** 7,13 ****
22c937
  a b d
22c937
  a d
22c937
  a
22c937
! a b c d x
22c937
! Y a b c d x
22c937
  
22c937
  a f
22c937
--- 7,13 ----
22c937
  a b d
22c937
  a d
22c937
  a
22c937
! a b c x
22c937
! Y a b c x
22c937
  
22c937
  a f
22c937
*** ../vim-7.4.564/src/testdir/test_close_count.in	2014-12-17 14:42:42.990240206 +0100
22c937
--- src/testdir/test_close_count.in	2015-01-07 15:33:21.950217606 +0100
22c937
***************
22c937
*** 28,34 ****
22c937
  :new
22c937
  :new
22c937
  :2wincmd w
22c937
! :-2close!
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
--- 28,34 ----
22c937
  :new
22c937
  :new
22c937
  :2wincmd w
22c937
! :-1close!
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
***************
22c937
*** 61,67 ****
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
! :9hide
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
--- 61,67 ----
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
! :$hide
22c937
  :let buffers = []
22c937
  :windo call add(buffers, bufnr('%'))
22c937
  :call add(tests, buffers)
22c937
*** ../vim-7.4.564/src/testdir/test_command_count.in	2015-01-07 13:15:40.609829496 +0100
22c937
--- src/testdir/test_command_count.in	2015-01-07 15:49:24.343016552 +0100
22c937
***************
22c937
*** 1,8 ****
22c937
  Test for user command counts	    vim: set ft=vim :
22c937
  
22c937
  STARTTEST
22c937
- :let g:lines = []
22c937
  :so tiny.vim
22c937
  :com -range=% RangeLines :call add(g:lines, 'RangeLines '.<line1>.' '.<line2>)
22c937
  :com -range -addr=arguments RangeArguments :call add(g:lines, 'RangeArguments '.<line1>.' '.<line2>)
22c937
  :com -range=% -addr=arguments RangeArgumentsAll :call add(g:lines, 'RangeArgumentsAll '.<line1>.' '.<line2>)
22c937
--- 1,8 ----
22c937
  Test for user command counts	    vim: set ft=vim :
22c937
  
22c937
  STARTTEST
22c937
  :so tiny.vim
22c937
+ :let g:lines = []
22c937
  :com -range=% RangeLines :call add(g:lines, 'RangeLines '.<line1>.' '.<line2>)
22c937
  :com -range -addr=arguments RangeArguments :call add(g:lines, 'RangeArguments '.<line1>.' '.<line2>)
22c937
  :com -range=% -addr=arguments RangeArgumentsAll :call add(g:lines, 'RangeArgumentsAll '.<line1>.' '.<line2>)
22c937
***************
22c937
*** 48,53 ****
22c937
--- 48,93 ----
22c937
  :'<,'>RangeLines
22c937
  :com -range=% -buffer LocalRangeLines :call add(g:lines, 'LocalRangeLines '.<line1>.' '.<line2>)
22c937
  :'<,'>LocalRangeLines
22c937
+ :b1
22c937
+ ENDTEST
22c937
+ 
22c937
+ STARTTEST
22c937
+ :call add(g:lines, '')
22c937
+ :%argd
22c937
+ :arga a b c d
22c937
+ :let v:errmsg = ''
22c937
+ :5argu
22c937
+ :call add(g:lines, '5argu ' . v:errmsg)
22c937
+ :$argu
22c937
+ :call add(g:lines, '4argu ' . expand('%:t'))
22c937
+ :let v:errmsg = ''
22c937
+ :1argu
22c937
+ :call add(g:lines, '1argu ' . expand('%:t'))
22c937
+ :let v:errmsg = ''
22c937
+ :100b
22c937
+ :call add(g:lines, '100b ' . v:errmsg)
22c937
+ :split|split|split|split
22c937
+ :let v:errmsg = ''
22c937
+ :0close
22c937
+ :call add(g:lines, '0close ' . v:errmsg)
22c937
+ :$wincmd w
22c937
+ :$close
22c937
+ :call add(g:lines, '$close ' . winnr())
22c937
+ :let v:errmsg = ''
22c937
+ :$+close
22c937
+ :call add(g:lines, '$+close ' . v:errmsg)
22c937
+ :$tabe
22c937
+ :call add(g:lines, '$tabe ' . tabpagenr())
22c937
+ :let v:errmsg = ''
22c937
+ :$+tabe
22c937
+ :call add(g:lines, '$+tabe ' . v:errmsg)
22c937
+ :only!
22c937
+ :e x
22c937
+ :0tabm
22c937
+ :normal 1gt
22c937
+ :call add(g:lines, '0tabm ' . expand('%:t'))
22c937
+ :tabonly!
22c937
+ :only!
22c937
  :e! test.out
22c937
  :call append(0, g:lines)
22c937
  :w|qa!
22c937
*** ../vim-7.4.564/src/testdir/test_command_count.ok	2015-01-07 13:15:40.609829496 +0100
22c937
--- src/testdir/test_command_count.ok	2015-01-07 15:49:19.223076159 +0100
22c937
***************
22c937
*** 17,19 ****
22c937
--- 17,30 ----
22c937
  RangeLines 2 5
22c937
  LocalRangeLines 2 5
22c937
  
22c937
+ 5argu E16: Invalid range
22c937
+ 4argu d
22c937
+ 1argu a
22c937
+ 100b E16: Invalid range
22c937
+ 0close E16: Invalid range
22c937
+ $close 4
22c937
+ $+close E16: Invalid range
22c937
+ $tabe 2
22c937
+ $+tabe E16: Invalid range
22c937
+ 0tabm x
22c937
+ 
22c937
*** ../vim-7.4.564/src/version.c	2015-01-07 14:43:35.728900384 +0100
22c937
--- src/version.c	2015-01-07 15:32:05.899101868 +0100
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     565,
22c937
  /**/
22c937
22c937
-- 
22c937
"I simultaneously try to keep my head in the clouds and my feet on the
22c937
ground.  Sometimes it's a stretch, though."              -- Larry Wall
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///