Karsten Hopp 5ee0df
To: vim-dev@vim.org
Karsten Hopp 5ee0df
Subject: Patch 7.2.132
Karsten Hopp 5ee0df
Fcc: outbox
Karsten Hopp 5ee0df
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 5ee0df
Mime-Version: 1.0
Karsten Hopp 5ee0df
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 5ee0df
Content-Transfer-Encoding: 8bit
Karsten Hopp 5ee0df
------------
Karsten Hopp 5ee0df
Karsten Hopp 5ee0df
Patch 7.2.132
Karsten Hopp 5ee0df
Problem:    When changing directory during a SwapExists autocmd freed memory
Karsten Hopp 5ee0df
            may be accessed. (Dominique Pelle)
Karsten Hopp 5ee0df
Solution:   Add the allbuf_lock flag.
Karsten Hopp 5ee0df
Files:      src/ex_getln.c, src/globals.h, src/fileio.c,
Karsten Hopp 5ee0df
            src/proto/ex_getln.pro
Karsten Hopp 5ee0df
    
Karsten Hopp 5ee0df
Karsten Hopp 5ee0df
*** ../vim-7.2.131/src/ex_getln.c	Mon Mar  2 02:11:09 2009
Karsten Hopp 5ee0df
--- src/ex_getln.c	Mon Mar  2 00:53:39 2009
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 2000,2007 ****
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
  #if defined(FEAT_AUTOCMD) || defined(PROTO)
Karsten Hopp 5ee0df
  /*
Karsten Hopp 5ee0df
!  * Check if "curbuf_lock" is set and return TRUE when it is and give an error
Karsten Hopp 5ee0df
!  * message.
Karsten Hopp 5ee0df
   */
Karsten Hopp 5ee0df
      int
Karsten Hopp 5ee0df
  curbuf_locked()
Karsten Hopp 5ee0df
--- 2000,2007 ----
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
  #if defined(FEAT_AUTOCMD) || defined(PROTO)
Karsten Hopp 5ee0df
  /*
Karsten Hopp 5ee0df
!  * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
Karsten Hopp 5ee0df
!  * and give an error message.
Karsten Hopp 5ee0df
   */
Karsten Hopp 5ee0df
      int
Karsten Hopp 5ee0df
  curbuf_locked()
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 2011,2016 ****
Karsten Hopp 5ee0df
--- 2011,2031 ----
Karsten Hopp 5ee0df
  	EMSG(_("E788: Not allowed to edit another buffer now"));
Karsten Hopp 5ee0df
  	return TRUE;
Karsten Hopp 5ee0df
      }
Karsten Hopp 5ee0df
+     return allbuf_locked();
Karsten Hopp 5ee0df
+ }
Karsten Hopp 5ee0df
+ 
Karsten Hopp 5ee0df
+ /*
Karsten Hopp 5ee0df
+  * Check if "allbuf_lock" is set and return TRUE when it is and give an error
Karsten Hopp 5ee0df
+  * message.
Karsten Hopp 5ee0df
+  */
Karsten Hopp 5ee0df
+     int
Karsten Hopp 5ee0df
+ allbuf_locked()
Karsten Hopp 5ee0df
+ {
Karsten Hopp 5ee0df
+     if (allbuf_lock > 0)
Karsten Hopp 5ee0df
+     {
Karsten Hopp 5ee0df
+ 	EMSG(_("E811: Not allowed to change buffer information now"));
Karsten Hopp 5ee0df
+ 	return TRUE;
Karsten Hopp 5ee0df
+     }
Karsten Hopp 5ee0df
      return FALSE;
Karsten Hopp 5ee0df
  }
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
*** ../vim-7.2.131/src/globals.h	Mon Mar  2 02:44:54 2009
Karsten Hopp 5ee0df
--- src/globals.h	Mon Mar  2 02:40:16 2009
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 619,624 ****
Karsten Hopp 5ee0df
--- 619,629 ----
Karsten Hopp 5ee0df
  EXTERN int	curbuf_lock INIT(= 0);
Karsten Hopp 5ee0df
  				/* non-zero when the current buffer can't be
Karsten Hopp 5ee0df
  				 * changed.  Used for FileChangedRO. */
Karsten Hopp 5ee0df
+ EXTERN int	allbuf_lock INIT(= 0);
Karsten Hopp 5ee0df
+ 				/* non-zero when no buffer name can be
Karsten Hopp 5ee0df
+ 				 * changed, no buffer can be deleted and
Karsten Hopp 5ee0df
+ 				 * current directory can't be changed.
Karsten Hopp 5ee0df
+ 				 * Used for SwapExists et al. */
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  #ifdef FEAT_EVAL
Karsten Hopp 5ee0df
  # define HAVE_SANDBOX
Karsten Hopp 5ee0df
*** ../vim-7.2.131/src/fileio.c	Wed Dec 31 16:20:54 2008
Karsten Hopp 5ee0df
--- src/fileio.c	Sun Mar  1 23:37:10 2009
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 69,75 ****
Karsten Hopp 5ee0df
  static int au_find_group __ARGS((char_u *name));
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
  # define AUGROUP_DEFAULT    -1	    /* default autocmd group */
Karsten Hopp 5ee0df
! # define AUGROUP_ERROR	    -2	    /* errornouse autocmd group */
Karsten Hopp 5ee0df
  # define AUGROUP_ALL	    -3	    /* all autocmd groups */
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
--- 69,75 ----
Karsten Hopp 5ee0df
  static int au_find_group __ARGS((char_u *name));
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
  # define AUGROUP_DEFAULT    -1	    /* default autocmd group */
Karsten Hopp 5ee0df
! # define AUGROUP_ERROR	    -2	    /* erroneous autocmd group */
Karsten Hopp 5ee0df
  # define AUGROUP_ALL	    -3	    /* all autocmd groups */
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 144,150 ****
Karsten Hopp 5ee0df
  # endif
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf));
Karsten Hopp 5ee0df
! 
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
      void
Karsten Hopp 5ee0df
  filemess(buf, name, s, attr)
Karsten Hopp 5ee0df
--- 144,152 ----
Karsten Hopp 5ee0df
  # endif
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf));
Karsten Hopp 5ee0df
! #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
! static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
Karsten Hopp 5ee0df
! #endif
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
      void
Karsten Hopp 5ee0df
  filemess(buf, name, s, attr)
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 295,300 ****
Karsten Hopp 5ee0df
--- 297,315 ----
Karsten Hopp 5ee0df
      int		conv_restlen = 0;	/* nr of bytes in conv_rest[] */
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
+ #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
+     /* Remember the initial values of curbuf, curbuf->b_ffname and
Karsten Hopp 5ee0df
+      * curbuf->b_fname to detect whether they are altered as a result of
Karsten Hopp 5ee0df
+      * executing nasty autocommands.  Also check if "fname" and "sfname"
Karsten Hopp 5ee0df
+      * point to one of these values. */
Karsten Hopp 5ee0df
+     buf_T   *old_curbuf = curbuf;
Karsten Hopp 5ee0df
+     char_u  *old_b_ffname = curbuf->b_ffname;
Karsten Hopp 5ee0df
+     char_u  *old_b_fname = curbuf->b_fname;
Karsten Hopp 5ee0df
+     int     using_b_ffname = (fname == curbuf->b_ffname)
Karsten Hopp 5ee0df
+ 					      || (sfname == curbuf->b_ffname);
Karsten Hopp 5ee0df
+     int     using_b_fname = (fname == curbuf->b_fname)
Karsten Hopp 5ee0df
+ 					       || (sfname == curbuf->b_fname);
Karsten Hopp 5ee0df
+ #endif
Karsten Hopp 5ee0df
      write_no_eol_lnum = 0;	/* in case it was set by the previous read */
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
      /*
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 589,595 ****
Karsten Hopp 5ee0df
--- 604,624 ----
Karsten Hopp 5ee0df
  #ifdef FEAT_QUICKFIX
Karsten Hopp 5ee0df
  		    if (!bt_dontwrite(curbuf))
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
+ 		    {
Karsten Hopp 5ee0df
  			check_need_swap(newfile);
Karsten Hopp 5ee0df
+ #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
+ 			/* SwapExists autocommand may mess things up */
Karsten Hopp 5ee0df
+ 			if (curbuf != old_curbuf
Karsten Hopp 5ee0df
+ 				|| (using_b_ffname
Karsten Hopp 5ee0df
+ 					&& (old_b_ffname != curbuf->b_ffname))
Karsten Hopp 5ee0df
+ 				|| (using_b_fname
Karsten Hopp 5ee0df
+ 					 && (old_b_fname != curbuf->b_fname)))
Karsten Hopp 5ee0df
+ 			{
Karsten Hopp 5ee0df
+ 			    EMSG(_(e_auchangedbuf));
Karsten Hopp 5ee0df
+ 			    return FAIL;
Karsten Hopp 5ee0df
+ 			}
Karsten Hopp 5ee0df
+ #endif
Karsten Hopp 5ee0df
+ 		    }
Karsten Hopp 5ee0df
  		    if (dir_of_file_exists(fname))
Karsten Hopp 5ee0df
  			filemess(curbuf, sfname, (char_u *)_("[New File]"), 0);
Karsten Hopp 5ee0df
  		    else
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 668,673 ****
Karsten Hopp 5ee0df
--- 697,713 ----
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
      {
Karsten Hopp 5ee0df
  	check_need_swap(newfile);
Karsten Hopp 5ee0df
+ #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
+ 	if (!read_stdin && (curbuf != old_curbuf
Karsten Hopp 5ee0df
+ 		|| (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
Karsten Hopp 5ee0df
+ 		|| (using_b_fname && (old_b_fname != curbuf->b_fname))))
Karsten Hopp 5ee0df
+ 	{
Karsten Hopp 5ee0df
+ 	    EMSG(_(e_auchangedbuf));
Karsten Hopp 5ee0df
+ 	    if (!read_buffer)
Karsten Hopp 5ee0df
+ 		close(fd);
Karsten Hopp 5ee0df
+ 	    return FAIL;
Karsten Hopp 5ee0df
+ 	}
Karsten Hopp 5ee0df
+ #endif
Karsten Hopp 5ee0df
  #ifdef UNIX
Karsten Hopp 5ee0df
  	/* Set swap file protection bits after creating it. */
Karsten Hopp 5ee0df
  	if (swap_mode > 0 && curbuf->b_ml.ml_mfp->mf_fname != NULL)
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 698,704 ****
Karsten Hopp 5ee0df
      {
Karsten Hopp 5ee0df
  	int	m = msg_scroll;
Karsten Hopp 5ee0df
  	int	n = msg_scrolled;
Karsten Hopp 5ee0df
- 	buf_T	*old_curbuf = curbuf;
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
  	/*
Karsten Hopp 5ee0df
  	 * The file must be closed again, the autocommands may want to change
Karsten Hopp 5ee0df
--- 738,743 ----
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 740,747 ****
Karsten Hopp 5ee0df
--- 779,791 ----
Karsten Hopp 5ee0df
  	/*
Karsten Hopp 5ee0df
  	 * Don't allow the autocommands to change the current buffer.
Karsten Hopp 5ee0df
  	 * Try to re-open the file.
Karsten Hopp 5ee0df
+ 	 *
Karsten Hopp 5ee0df
+ 	 * Don't allow the autocommands to change the buffer name either
Karsten Hopp 5ee0df
+ 	 * (cd for example) if it invalidates fname or sfname.
Karsten Hopp 5ee0df
  	 */
Karsten Hopp 5ee0df
  	if (!read_stdin && (curbuf != old_curbuf
Karsten Hopp 5ee0df
+ 		|| (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
Karsten Hopp 5ee0df
+ 		|| (using_b_fname && (old_b_fname != curbuf->b_fname))
Karsten Hopp 5ee0df
  		|| (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0))
Karsten Hopp 5ee0df
  	{
Karsten Hopp 5ee0df
  	    --no_wait_return;
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 6320,6326 ****
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
      if (!stuff_empty() || global_busy || !typebuf_typed()
Karsten Hopp 5ee0df
  #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
! 			|| autocmd_busy || curbuf_lock > 0
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  					)
Karsten Hopp 5ee0df
  	need_check_timestamps = TRUE;		/* check later */
Karsten Hopp 5ee0df
--- 6364,6370 ----
Karsten Hopp 5ee0df
  
Karsten Hopp 5ee0df
      if (!stuff_empty() || global_busy || !typebuf_typed()
Karsten Hopp 5ee0df
  #ifdef FEAT_AUTOCMD
Karsten Hopp 5ee0df
! 			|| autocmd_busy || curbuf_lock > 0 || allbuf_lock > 0
Karsten Hopp 5ee0df
  #endif
Karsten Hopp 5ee0df
  					)
Karsten Hopp 5ee0df
  	need_check_timestamps = TRUE;		/* check later */
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 6522,6529 ****
Karsten Hopp 5ee0df
--- 6566,6575 ----
Karsten Hopp 5ee0df
  	    set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1);
Karsten Hopp 5ee0df
  	    set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1);
Karsten Hopp 5ee0df
  # endif
Karsten Hopp 5ee0df
+ 	    ++allbuf_lock;
Karsten Hopp 5ee0df
  	    n = apply_autocmds(EVENT_FILECHANGEDSHELL,
Karsten Hopp 5ee0df
  				      buf->b_fname, buf->b_fname, FALSE, buf);
Karsten Hopp 5ee0df
+ 	    --allbuf_lock;
Karsten Hopp 5ee0df
  	    busy = FALSE;
Karsten Hopp 5ee0df
  	    if (n)
Karsten Hopp 5ee0df
  	    {
Karsten Hopp 5ee0df
*** ../vim-7.2.131/src/proto/ex_getln.pro	Fri Nov 28 10:59:57 2008
Karsten Hopp 5ee0df
--- src/proto/ex_getln.pro	Sun Mar  1 00:27:12 2009
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 4,9 ****
Karsten Hopp 5ee0df
--- 4,10 ----
Karsten Hopp 5ee0df
  int text_locked __ARGS((void));
Karsten Hopp 5ee0df
  void text_locked_msg __ARGS((void));
Karsten Hopp 5ee0df
  int curbuf_locked __ARGS((void));
Karsten Hopp 5ee0df
+ int allbuf_locked __ARGS((void));
Karsten Hopp 5ee0df
  char_u *getexline __ARGS((int c, void *dummy, int indent));
Karsten Hopp 5ee0df
  char_u *getexmodeline __ARGS((int promptc, void *dummy, int indent));
Karsten Hopp 5ee0df
  int cmdline_overstrike __ARGS((void));
Karsten Hopp 5ee0df
*** ../vim-7.2.131/src/version.c	Wed Mar  4 04:11:56 2009
Karsten Hopp 5ee0df
--- src/version.c	Thu Mar  5 03:08:54 2009
Karsten Hopp 5ee0df
***************
Karsten Hopp 5ee0df
*** 678,679 ****
Karsten Hopp 5ee0df
--- 678,681 ----
Karsten Hopp 5ee0df
  {   /* Add new patch number below this line */
Karsten Hopp 5ee0df
+ /**/
Karsten Hopp 5ee0df
+     132,
Karsten Hopp 5ee0df
  /**/
Karsten Hopp 5ee0df
Karsten Hopp 5ee0df
-- 
Karsten Hopp 5ee0df
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 5ee0df
168. You have your own domain name.
Karsten Hopp 5ee0df
Karsten Hopp 5ee0df
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 5ee0df
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 5ee0df
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 5ee0df
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///