]> git.pld-linux.org Git - packages/vim.git/blob - 7.2.440
- new
[packages/vim.git] / 7.2.440
1 To: vim-dev@vim.org
2 Subject: Patch 7.2.440
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.2.440
11 Problem:    Calling a function through a funcref, where the function deletes
12             the funcref, leads to an invalid memory access.
13 Solution:   Make a copy of the function name. (Lech Lorens)
14 Files:      src/eval.c, src/testdir/test34.in, src/testdir/test34.ok
15
16
17 *** ../vim-7.2.439/src/eval.c   2010-05-16 13:26:19.000000000 +0200
18 --- src/eval.c  2010-05-28 22:01:07.000000000 +0200
19 ***************
20 *** 464,470 ****
21   static int find_internal_func __ARGS((char_u *name));
22   static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
23   static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
24 ! static int call_func __ARGS((char_u *name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
25   static void emsg_funcname __ARGS((char *ermsg, char_u *name));
26   static int non_zero_arg __ARGS((typval_T *argvars));
27   
28 --- 464,470 ----
29   static int find_internal_func __ARGS((char_u *name));
30   static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
31   static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
32 ! static int call_func __ARGS((char_u *func_name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
33   static void emsg_funcname __ARGS((char *ermsg, char_u *name));
34   static int non_zero_arg __ARGS((typval_T *argvars));
35   
36 ***************
37 *** 7997,8005 ****
38    * Also returns OK when an error was encountered while executing the function.
39    */
40       static int
41 ! call_func(name, len, rettv, argcount, argvars, firstline, lastline,
42                                                 doesrange, evaluate, selfdict)
43 !     char_u    *name;          /* name of the function */
44       int               len;            /* length of "name" */
45       typval_T  *rettv;         /* return value goes here */
46       int               argcount;       /* number of "argvars" */
47 --- 7997,8005 ----
48    * Also returns OK when an error was encountered while executing the function.
49    */
50       static int
51 ! call_func(func_name, len, rettv, argcount, argvars, firstline, lastline,
52                                                 doesrange, evaluate, selfdict)
53 !     char_u    *func_name;     /* name of the function */
54       int               len;            /* length of "name" */
55       typval_T  *rettv;         /* return value goes here */
56       int               argcount;       /* number of "argvars" */
57 ***************
58 *** 8023,8040 ****
59       int               i;
60       int               llen;
61       ufunc_T   *fp;
62 -     int               cc;
63   #define FLEN_FIXED 40
64       char_u    fname_buf[FLEN_FIXED + 1];
65       char_u    *fname;
66   
67       /*
68        * In a script change <SID>name() and s:name() to K_SNR 123_name().
69        * Change <SNR>123_name() to K_SNR 123_name().
70        * Use fname_buf[] when it fits, otherwise allocate memory (slow).
71        */
72 -     cc = name[len];
73 -     name[len] = NUL;
74       llen = eval_fname_script(name);
75       if (llen > 0)
76       {
77 --- 8023,8044 ----
78       int               i;
79       int               llen;
80       ufunc_T   *fp;
81   #define FLEN_FIXED 40
82       char_u    fname_buf[FLEN_FIXED + 1];
83       char_u    *fname;
84 +     char_u    *name;
85
86 +     /* Make a copy of the name, if it comes from a funcref variable it could
87 +      * be changed or deleted in the called function. */
88 +     name = vim_strnsave(func_name, len);
89 +     if (name == NULL)
90 +       return ret;
91   
92       /*
93        * In a script change <SID>name() and s:name() to K_SNR 123_name().
94        * Change <SNR>123_name() to K_SNR 123_name().
95        * Use fname_buf[] when it fits, otherwise allocate memory (slow).
96        */
97       llen = eval_fname_script(name);
98       if (llen > 0)
99       {
100 ***************
101 *** 8205,8213 ****
102         }
103       }
104   
105 -     name[len] = cc;
106       if (fname != name && fname != fname_buf)
107         vim_free(fname);
108   
109       return ret;
110   }
111 --- 8209,8217 ----
112         }
113       }
114   
115       if (fname != name && fname != fname_buf)
116         vim_free(fname);
117 +     vim_free(name);
118   
119       return ret;
120   }
121 *** ../vim-7.2.439/src/testdir/test34.in        2007-09-25 17:59:15.000000000 +0200
122 --- src/testdir/test34.in       2010-05-28 21:54:36.000000000 +0200
123 ***************
124 *** 35,40 ****
125 --- 35,45 ----
126   :  let g:counter = 0
127   :  return ''
128   :endfunc
129 + :func FuncWithRef(a)
130 + :  unlet g:FuncRef
131 + :  return a:a
132 + :endfunc
133 + :let g:FuncRef=function("FuncWithRef")
134   :let counter = 0
135   :inoremap <expr> ( ListItem()
136   :inoremap <expr> [ ListReset()
137 ***************
138 *** 47,52 ****
139 --- 52,58 ----
140    \12=retval
141    \12=Compute(45, 5, "retval")
142    \12=retval
143 +  \12=g:FuncRef(333)
144   
145   XX+-XX
146   ---*---
147 *** ../vim-7.2.439/src/testdir/test34.ok        2006-04-30 20:49:40.000000000 +0200
148 --- src/testdir/test34.ok       2010-05-28 21:56:03.000000000 +0200
149 ***************
150 *** 1,4 ****
151 ! xxx4asdf fail nop ok 9
152   XX111XX
153   ---222---
154   1. one
155 --- 1,4 ----
156 ! xxx4asdf fail nop ok 9 333
157   XX111XX
158   ---222---
159   1. one
160 *** ../vim-7.2.439/src/version.c        2010-05-28 21:31:51.000000000 +0200
161 --- src/version.c       2010-05-28 22:03:30.000000000 +0200
162 ***************
163 *** 683,684 ****
164 --- 683,686 ----
165   {   /* Add new patch number below this line */
166 + /**/
167 +     440,
168   /**/
169
170 -- 
171 Nobody will ever need more than 640 kB RAM.
172                 -- Bill Gates, 1983
173 Windows 98 requires 16 MB RAM.
174                 -- Bill Gates, 1999
175 Logical conclusion: Nobody will ever need Windows 98.
176
177  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
178 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
179 \\\        download, build and distribute -- http://www.A-A-P.org        ///
180  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.057857 seconds and 3 git commands to generate.