From 76c34d7b2fc2d737384796d807778a41db92503d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 5 Nov 2016 09:50:53 +0100 Subject: [PATCH] - block access to private and protected data for the external variabler getter functions. - fixed: The state index comparison against 0 was broken. - fixed: Resolving codegen nodes must set the strictness flag per function so that ZSCRIPT and DECORATE are done properly. --- src/p_actionfunctions.cpp | 4 ++-- src/p_setup.cpp | 2 +- src/scripting/codegeneration/codegen.cpp | 2 +- src/scripting/vm/vmbuilder.cpp | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 9ed20daf8..1cfc44ae2 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -5031,7 +5031,7 @@ static PField *GetVar(DObject *self, FName varname) { PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); - if (var == NULL || (var->Flags & VARF_Native) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) + if (var == NULL || (var->Flags & (VARF_Native | VARF_Private | VARF_Protected | VARF_Static)) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) { Printf("%s is not a user variable in class %s\n", varname.GetChars(), self->GetClass()->TypeName.GetChars()); @@ -5080,7 +5080,7 @@ static PField *GetArrayVar(DObject *self, FName varname, int pos) { PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); - if (var == NULL || (var->Flags & VARF_Native) || + if (var == NULL || (var->Flags & (VARF_Native | VARF_Private | VARF_Protected | VARF_Static)) || !var->Type->IsKindOf(RUNTIME_CLASS(PArray)) || !static_cast(var->Type)->ElementType->IsKindOf(RUNTIME_CLASS(PBasicType))) { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index aafed854b..11aef9d8d 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1688,7 +1688,7 @@ static void SetMapThingUserData(AActor *actor, unsigned udi) udi++; - if (var == NULL || (var->Flags & VARF_Native) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) + if (var == NULL || (var->Flags & (VARF_Native|VARF_Private|VARF_Protected|VARF_Static)) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) { DPrintf(DMSG_WARNING, "%s is not a user variable in class %s\n", varname.GetChars(), actor->GetClass()->TypeName.GetChars()); diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 4111805ea..db6355f84 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -7886,7 +7886,7 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx) delete this; return nullptr; } - else if (Index->isConstant() && static_cast(Index) < 0) + else if (Index->isConstant() && static_cast(Index)->GetValue() < 0) { ScriptPosition.Message(MSG_ERROR, "State index must be positive"); delete this; diff --git a/src/scripting/vm/vmbuilder.cpp b/src/scripting/vm/vmbuilder.cpp index 41ec4b920..5b792e7cc 100644 --- a/src/scripting/vm/vmbuilder.cpp +++ b/src/scripting/vm/vmbuilder.cpp @@ -713,6 +713,7 @@ void FFunctionBuildList::Build() ctx.FunctionArgs.Push(local); } + FScriptPosition::StrictErrors = !item.FromDecorate; item.Code = item.Code->Resolve(ctx); item.Proto = ctx.ReturnProto; @@ -758,4 +759,6 @@ void FFunctionBuildList::Build() fprintf(dump, "\n*************************************************************************\n%i code bytes\n", codesize * 4); fclose(dump); } + FScriptPosition::StrictErrors = false; + } \ No newline at end of file