0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.1867: Vim9: access to interface statics possible

Problem:  Vim9: access to interface statics possible
Solution: Prevent direct access to interface statics

closes: #13007

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
This commit is contained in:
Ernie Rael
2023-09-04 22:30:41 +02:00
committed by Christian Brabandt
parent dccc29c228
commit 18143d3111
12 changed files with 332 additions and 25 deletions

View File

@@ -220,9 +220,11 @@ add_members_to_class(
* "cl" implementing that interface.
*/
int
object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl)
object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl,
int is_static)
{
if (idx > (is_method ? itf->class_obj_method_count
if (idx >= (is_method ? itf->class_obj_method_count
: is_static ? itf->class_class_member_count
: itf->class_obj_member_count))
{
siemsg("index %d out of range for interface %s", idx, itf->class_name);
@@ -245,8 +247,28 @@ object_index_from_itf_index(class_T *itf, int is_method, int idx, class_T *cl)
cl->class_name, itf->class_name);
return 0;
}
int *table = (int *)(i2c + 1);
return table[idx];
if (is_static)
{
// TODO: Need a table for fast lookup?
char_u *name = itf->class_class_members[idx].ocm_name;
for (int i = 0; i < i2c->i2c_class->class_class_member_count; ++i)
{
ocmember_T *m = &i2c->i2c_class->class_class_members[i];
if (STRCMP(name, m->ocm_name) == 0)
{
return i;
}
}
siemsg("class %s, interface %s, static %s not found",
cl->class_name, itf->class_name, name);
return 0;
}
else
{
// A table follows the i2c for the class
int *table = (int *)(i2c + 1);
return table[idx];
}
}
/*
@@ -1808,6 +1830,12 @@ class_object_index(
semsg(_(e_cannot_access_private_member_str), m->ocm_name);
return FAIL;
}
if ((cl->class_flags & CLASS_INTERFACE) != 0)
{
semsg(_(e_interface_static_direct_access_str),
cl->class_name, m->ocm_name);
return FAIL;
}
typval_T *tv = &cl->class_members_tv[i];
copy_tv(tv, rettv);