summaryrefslogtreecommitdiffstats
path: root/gvim/vim-7.2/7.2.132
blob: 69e19ee45d638518aae34d52feb3ee5fdcd7ff5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
To: vim-dev@vim.org
Subject: Patch 7.2.132
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.132
Problem:    When changing directory during a SwapExists autocmd freed memory
            may be accessed. (Dominique Pelle)
Solution:   Add the allbuf_lock flag.
Files:      src/ex_getln.c, src/globals.h, src/fileio.c,
            src/proto/ex_getln.pro
    

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

-- 
hundred-and-one symptoms of being an internet addict:
168. You have your own domain name.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///