summaryrefslogtreecommitdiff
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-01 21:21:55 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-01 21:21:55 +0200
commit6f1d2aa437744a7cb0206fdaa543a788c5a56c79 (patch)
tree69fa87e33af45f6763679098bda0011e83041e19 /src/dict.c
parent6a43b37b760347b9a1bedf12e41b458000922969 (diff)
downloadvim-git-6f1d2aa437744a7cb0206fdaa543a788c5a56c79.tar.gz
patch 8.2.2920: still a way to shadow a builtin functionv8.2.2920
Problem: Still a way to shadow a builtin function. (Yasuhiro Matsumoto) Solution: Check the key when using extend(). (issue #8302)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/dict.c b/src/dict.c
index 922da473c..876eeea49 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -345,12 +345,28 @@ dict_copy(dict_T *orig, int deep, int copyID)
}
/*
+ * Check for adding a function to g: or s:.
+ * If the name is wrong give an error message and return TRUE.
+ */
+ int
+dict_wrong_func_name(dict_T *d, typval_T *tv, char_u *name)
+{
+ return (d == get_globvar_dict()
+ || (SCRIPT_ID_VALID(current_sctx.sc_sid)
+ && d == &SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict))
+ && (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
+ && var_wrong_func_name(name, TRUE);
+}
+
+/*
* Add item "item" to Dictionary "d".
* Returns FAIL when out of memory and when key already exists.
*/
int
dict_add(dict_T *d, dictitem_T *item)
{
+ if (dict_wrong_func_name(d, &item->di_tv, item->di_key))
+ return FAIL;
return hash_add(&d->dv_hashtab, item->di_key);
}
@@ -1109,6 +1125,8 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
break;
+ if (dict_wrong_func_name(d1, &HI2DI(hi2)->di_tv, hi2->hi_key))
+ break;
clear_tv(&di1->di_tv);
copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv);
}