Skip to content

Commit fefc5da

Browse files
authored
Merge pull request #7885 from LandSandBoat/getfurthestvalidposition-safety
Add null check to Lua functions with userdata params
2 parents 55fe5b8 + cf31628 commit fefc5da

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/map/lua/lua_baseentity.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11574,6 +11574,12 @@ uint8 CLuaBaseEntity::checkSoloPartyAlliance()
1157411574

1157511575
bool CLuaBaseEntity::checkKillCredit(CLuaBaseEntity* PLuaBaseEntity, sol::object const& minRange)
1157611576
{
11577+
if (PLuaBaseEntity == nullptr)
11578+
{
11579+
ShowWarning("CLuaBaseEntity::checkKillCredit() - PLuaBaseEntity received null value.");
11580+
return false;
11581+
}
11582+
1157711583
if (m_PBaseEntity->objtype != TYPE_PC || (PLuaBaseEntity && PLuaBaseEntity->GetBaseEntity()->objtype != TYPE_MOB))
1157811584
{
1157911585
ShowWarning("CLuaBaseEntity::checkKillCredit() - Non-PC type calling function, or PLuaBaseEntity is not a MOB.");
@@ -11611,6 +11617,12 @@ bool CLuaBaseEntity::checkKillCredit(CLuaBaseEntity* PLuaBaseEntity, sol::object
1161111617
************************************************************************/
1161211618
uint8 CLuaBaseEntity::checkDifficulty(CLuaBaseEntity* PLuaBaseEntity)
1161311619
{
11620+
if (PLuaBaseEntity == nullptr)
11621+
{
11622+
ShowWarning("CLuaBaseEntity::checkDifficulty() - PLuaBaseEntity received null value.");
11623+
return 0;
11624+
}
11625+
1161411626
CMobEntity* PMob = dynamic_cast<CMobEntity*>(PLuaBaseEntity->GetBaseEntity());
1161511627
CCharEntity* PChar = dynamic_cast<CCharEntity*>(m_PBaseEntity);
1161611628

src/map/lua/luautils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,6 +4964,12 @@ namespace luautils
49644964

49654965
sol::table GetFurthestValidPosition(CLuaBaseEntity* fromTarget, float distance, float theta)
49664966
{
4967+
if (!fromTarget || !fromTarget->GetBaseEntity())
4968+
{
4969+
ShowError("luautils::GetFurthestValidPosition: fromTarget is null or invalid");
4970+
return sol::lua_nil;
4971+
}
4972+
49674973
CBaseEntity* entity = fromTarget->GetBaseEntity();
49684974
position_t pos = nearPosition(entity->loc.p, distance, theta);
49694975

0 commit comments

Comments
 (0)