comparison src/vim9execute.c @ 33173:9efd99a717c1 v9.0.1867

patch 9.0.1867: Vim9: access to interface statics possible Commit: https://github.com/vim/vim/commit/18143d3111b2122c7a94ca51085a60b3073cb139 Author: Ernie Rael <errael@raelity.com> Date: Mon Sep 4 22:30:41 2023 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Mon, 04 Sep 2023 22:45:04 +0200
parents aecd03679315
children ea3f1e0ee5f3
comparison
equal deleted inserted replaced
33172:6564d48fe98a 33173:9efd99a717c1
2314 2314
2315 otv = (typval_T *)(obj + 1); 2315 otv = (typval_T *)(obj + 1);
2316 class_T *itf = iptr->isn_arg.storeindex.si_class; 2316 class_T *itf = iptr->isn_arg.storeindex.si_class;
2317 if (itf != NULL) 2317 if (itf != NULL)
2318 // convert interface member index to class member index 2318 // convert interface member index to class member index
2319 lidx = object_index_from_itf_index(itf, FALSE, 2319 lidx = object_index_from_itf_index(itf, FALSE, lidx,
2320 lidx, obj->obj_class); 2320 obj->obj_class, FALSE);
2321 } 2321 }
2322 else 2322 else
2323 { 2323 {
2324 // VAR_CLASS 2324 // VAR_CLASS
2325 class_T *class = tv_dest->vval.v_class; 2325 class_T *class = tv_dest->vval.v_class;
4259 object_T *obj = tv->vval.v_object; 4259 object_T *obj = tv->vval.v_object;
4260 class_T *cl = obj->obj_class; 4260 class_T *cl = obj->obj_class;
4261 4261
4262 // convert the interface index to the object index 4262 // convert the interface index to the object index
4263 int idx = object_index_from_itf_index(mfunc->cmf_itf, 4263 int idx = object_index_from_itf_index(mfunc->cmf_itf,
4264 TRUE, mfunc->cmf_idx, cl); 4264 TRUE, mfunc->cmf_idx, cl,
4265 FALSE);
4265 4266
4266 if (call_ufunc(cl->class_obj_methods[idx], NULL, 4267 if (call_ufunc(cl->class_obj_methods[idx], NULL,
4267 mfunc->cmf_argcount, ectx, NULL, NULL) == FAIL) 4268 mfunc->cmf_argcount, ectx, NULL, NULL) == FAIL)
4268 goto on_error; 4269 goto on_error;
4269 } 4270 }
4408 object_T *obj = tv->vval.v_object; 4409 object_T *obj = tv->vval.v_object;
4409 class_T *cl = obj->obj_class; 4410 class_T *cl = obj->obj_class;
4410 4411
4411 // convert the interface index to the object index 4412 // convert the interface index to the object index
4412 int idx = object_index_from_itf_index(extra->fre_class, 4413 int idx = object_index_from_itf_index(extra->fre_class,
4413 TRUE, extra->fre_method_idx, cl); 4414 TRUE, extra->fre_method_idx, cl,
4415 FALSE);
4414 ufunc = cl->class_obj_methods[idx]; 4416 ufunc = cl->class_obj_methods[idx];
4415 } 4417 }
4416 else if (extra == NULL || extra->fre_func_name == NULL) 4418 else if (extra == NULL || extra->fre_func_name == NULL)
4417 { 4419 {
4418 dfunc_T *pt_dfunc = ((dfunc_T *)def_functions.ga_data) 4420 dfunc_T *pt_dfunc = ((dfunc_T *)def_functions.ga_data)
5387 SOURCING_LNUM = iptr->isn_lnum; 5389 SOURCING_LNUM = iptr->isn_lnum;
5388 emsg(_(e_using_null_object)); 5390 emsg(_(e_using_null_object));
5389 goto on_error; 5391 goto on_error;
5390 } 5392 }
5391 5393
5394 int is_static = iptr->isn_arg.classmember.cm_static;
5392 int idx; 5395 int idx;
5393 if (iptr->isn_type == ISN_GET_OBJ_MEMBER) 5396 if (iptr->isn_type == ISN_GET_OBJ_MEMBER)
5394 idx = iptr->isn_arg.number; 5397 idx = iptr->isn_arg.classmember.cm_idx;
5395 else 5398 else
5396 { 5399 {
5397 idx = iptr->isn_arg.classmember.cm_idx; 5400 idx = iptr->isn_arg.classmember.cm_idx;
5398 // convert the interface index to the object index 5401 // convert the interface index to the object index
5399 idx = object_index_from_itf_index( 5402 idx = object_index_from_itf_index(
5400 iptr->isn_arg.classmember.cm_class, 5403 iptr->isn_arg.classmember.cm_class,
5401 FALSE, idx, obj->obj_class); 5404 FALSE, idx, obj->obj_class, is_static);
5402 } 5405 }
5403 5406
5404 // the members are located right after the object struct 5407 // The members are located right after the object struct.
5405 typval_T *mtv = ((typval_T *)(obj + 1)) + idx; 5408 typval_T *mtv;
5409 if (is_static)
5410 mtv = &obj->obj_class->class_members_tv[idx];
5411 else
5412 mtv = ((typval_T *)(obj + 1)) + idx;
5406 copy_tv(mtv, tv); 5413 copy_tv(mtv, tv);
5407 5414
5408 // Unreference the object after getting the member, it may 5415 // Unreference the object after getting the member, it may
5409 // be freed. 5416 // be freed.
5410 object_unref(obj); 5417 object_unref(obj);