diff src/vim9expr.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 2b5cc29b0a0e
children 52b121d4feb5
line wrap: on
line diff
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -407,8 +407,27 @@ compile_class_object_index(cctx_T *cctx,
 
 		*arg = name_end;
 		if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
-		    return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type);
-		return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type);
+		    return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
+									FALSE);
+		return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, FALSE);
+	    }
+	}
+
+	for (int i = 0; i < cl->class_class_member_count; ++i)
+	{
+	    ocmember_T *m = &cl->class_class_members[i];
+	    if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
+	    {
+		if (*name == '_' && !inside_class(cctx, cl))
+		{
+		    semsg(_(e_cannot_access_private_member_str), m->ocm_name);
+		    return FAIL;
+		}
+		*arg = name_end;
+		if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
+		    return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
+									TRUE);
+		return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, TRUE);
 	    }
 	}
 
@@ -439,6 +458,13 @@ compile_class_object_index(cctx_T *cctx,
 	    ocmember_T *m = &cl->class_class_members[idx];
 	    if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
 	    {
+		// Note: type->tt_type = VAR_CLASS
+		if ((cl->class_flags & CLASS_INTERFACE) != 0)
+		{
+		    semsg(_(e_interface_static_direct_access_str),
+						cl->class_name, m->ocm_name);
+		    return FAIL;
+		}
 		if (*name == '_' && !inside_class(cctx, cl))
 		{
 		    semsg(_(e_cannot_access_private_member_str), m->ocm_name);