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