From 36a97d441bbb164c59d095aef1ef73f41fa38247 Mon Sep 17 00:00:00 2001 From: Kiryu144 <123davidLP@gmail.com> Date: Fri, 23 Jul 2021 11:14:01 +0200 Subject: Added y bounds checking for cPlayer::PlaceBlock (#5194) --- src/Bindings/ManualBindings.cpp | 68 +++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 16 deletions(-) (limited to 'src/Bindings/ManualBindings.cpp') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 37fc20d39..08f324aec 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1595,27 +1595,56 @@ static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S) -static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S) +static int tolua_cPlayer_GetUUID(lua_State * tolua_S) { - // Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool + // Check the params: + cLuaState L(tolua_S); + if (!L.CheckParamSelf("cPlayer")) + { + return 0; + } + // Get the params: + cPlayer * Self = nullptr; + L.GetStackValue(1, Self); + + // Return the UUID as a string + L.Push(Self->GetUUID().ToShortString()); + return 1; +} + + + + + +static int tolua_cPlayer_PlaceBlock(lua_State * tolua_S) +{ // Check the params: cLuaState L(tolua_S); if ( - !L.CheckParamUserTable(1, "cPlayer") || - !L.CheckParamString (2, 3) || - !L.CheckParamEnd (4) + !L.CheckParamSelf("cPlayer") || + !L.CheckParamUserType(2, "Vector3") || + !L.CheckParamNumber(3, 4) || + !L.CheckParamEnd(5) ) { return 0; } // Get the params: - AString Permission, Template; - L.GetStackValues(2, Permission, Template); + cPlayer * Self; + Vector3i Position; + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + L.GetStackValues(1, Self, Position, BlockType, BlockMeta); - // Push the result of the match: - L.Push(cPlayer::PermissionMatches(StringSplit(Permission, "."), StringSplit(Template, "."))); + if (!cChunkDef::IsValidHeight(Position.y)) + { + return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'position'"); + } + + // Return the result of placement: + L.Push(Self->PlaceBlock(Position, BlockType, BlockMeta)); return 1; } @@ -1623,21 +1652,27 @@ static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S) -static int tolua_cPlayer_GetUUID(lua_State * tolua_S) +static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S) { + // Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool + // Check the params: cLuaState L(tolua_S); - if (!L.CheckParamSelf("cPlayer")) + if ( + !L.CheckParamUserTable(1, "cPlayer") || + !L.CheckParamString (2, 3) || + !L.CheckParamEnd (4) + ) { return 0; } // Get the params: - cPlayer * Self = nullptr; - L.GetStackValue(1, Self); + AString Permission, Template; + L.GetStackValues(2, Permission, Template); - // Return the UUID as a string - L.Push(Self->GetUUID().ToShortString()); + // Push the result of the match: + L.Push(cPlayer::PermissionMatches(StringSplit(Permission, "."), StringSplit(Template, "."))); return 1; } @@ -4601,8 +4636,9 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cPlayer"); tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions); tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions); - tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches); tolua_function(tolua_S, "GetUUID", tolua_cPlayer_GetUUID); + tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches); + tolua_function(tolua_S, "PlaceBlock", tolua_cPlayer_PlaceBlock); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlugin"); -- cgit v1.2.3