1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: It's possible to assign to a read-only member of a dict.
12 It's possible to create a global variable "0". (ZyX)
13 It's possible to add a v: variable with ":let v:.name = 1".
14 Solution: Add check for dict item being read-only.
15 Check the name of g: variables.
16 Disallow adding v: variables.
20 *** ../vim-7.3.145/src/eval.c 2011-02-01 13:48:47.000000000 +0100
21 --- src/eval.c 2011-03-27 15:56:44.000000000 +0200
25 static void set_var __ARGS((char_u *name, typval_T *varp, int copy));
26 static int var_check_ro __ARGS((int flags, char_u *name));
27 static int var_check_fixed __ARGS((int flags, char_u *name));
28 + static int var_check_func_name __ARGS((char_u *name, int new_var));
29 + static int valid_varname __ARGS((char_u *varname));
30 static int tv_check_lock __ARGS((int lock, char_u *name));
31 static int item_copy __ARGS((typval_T *from, typval_T *to, int deep, int copyID));
32 static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags));
37 lp->ll_dict = lp->ll_tv->vval.v_dict;
38 lp->ll_di = dict_find(lp->ll_dict, key, len);
40 + /* When assigning to g: check that a function and variable name is
42 + if (rettv != NULL && lp->ll_dict == &globvardict)
44 + if (rettv->v_type == VAR_FUNC
45 + && var_check_func_name(key, lp->ll_di == NULL))
47 + if (!valid_varname(key))
51 if (lp->ll_di == NULL)
53 + /* Can't add "v:" variable. */
54 + if (lp->ll_dict == &vimvardict)
56 + EMSG2(_(e_illvar), name);
60 /* Key does not exist in dict: may need to add it. */
61 if (*p == '[' || *p == '.' || unlet)
69 + /* existing variable, need to check if it can be changed */
70 + else if (var_check_ro(lp->ll_di->di_flags, name))
75 lp->ll_tv = &lp->ll_di->di_tv;
83 ht = find_var_ht(name, &varname);
84 if (ht == NULL || *varname == NUL)
89 v = find_var_in_ht(ht, varname, TRUE);
91 ! if (tv->v_type == VAR_FUNC)
93 ! if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':')
94 ! && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
95 ! ? name[2] : name[0]))
97 ! EMSG2(_("E704: Funcref variable name must start with a capital: %s"), name);
100 ! /* Don't allow hiding a function. When "v" is not NULL we might be
101 ! * assigning another function to the same var, the type is checked
103 ! if (v == NULL && function_exists(name))
105 ! EMSG2(_("E705: Variable name conflicts with existing function: %s"),
115 v = find_var_in_ht(ht, varname, TRUE);
117 ! if (tv->v_type == VAR_FUNC && var_check_func_name(name, v == NULL))
126 /* Make sure the variable name is valid. */
127 ! for (p = varname; *p != NUL; ++p)
128 ! if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
129 ! && *p != AUTOLOAD_CHAR)
131 ! EMSG2(_(e_illvar), varname);
135 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
140 /* Make sure the variable name is valid. */
141 ! if (!valid_varname(varname))
144 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
152 + * Check if a funcref is assigned to a valid variable name.
153 + * Return TRUE and give an error if not.
156 + var_check_func_name(name, new_var)
157 + char_u *name; /* points to start of variable name */
158 + int new_var; /* TRUE when creating the variable */
160 + if (!(vim_strchr((char_u *)"wbs", name[0]) != NULL && name[1] == ':')
161 + && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
162 + ? name[2] : name[0]))
164 + EMSG2(_("E704: Funcref variable name must start with a capital: %s"),
168 + /* Don't allow hiding a function. When "v" is not NULL we might be
169 + * assigning another function to the same var, the type is checked
171 + if (new_var && function_exists(name))
173 + EMSG2(_("E705: Variable name conflicts with existing function: %s"),
181 + * Check if a variable name is valid.
182 + * Return FALSE and give an error if not.
185 + valid_varname(varname)
190 + for (p = varname; *p != NUL; ++p)
191 + if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
192 + && *p != AUTOLOAD_CHAR)
194 + EMSG2(_(e_illvar), varname);
201 * Return TRUE if typeval "tv" is set to be locked (immutable).
202 * Also give an error message, using "name".
204 *** ../vim-7.3.145/src/version.c 2011-03-26 18:32:00.000000000 +0100
205 --- src/version.c 2011-03-27 16:01:03.000000000 +0200
209 { /* Add new patch number below this line */
215 ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot.
216 King of all Britons, defeator of the Saxons, sovereign of all England!
219 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
221 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
222 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
223 \\\ an exciting new programming language -- http://www.Zimbu.org ///
224 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///