Check hp_max > 0 for entities (#12667)

master
Lars Müller 2022-08-13 16:35:41 +02:00 committed by GitHub
parent 3132efcc01
commit 0e439b2fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -196,6 +196,9 @@ void read_object_properties(lua_State *L, int index,
int hp_max = 0;
if (getintfield(L, -1, "hp_max", hp_max)) {
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
// hp_max = 0 is sometimes used as a hack to keep players dead, only validate for entities
if (prop->hp_max == 0 && sao->getType() != ACTIVEOBJECT_TYPE_PLAYER)
throw LuaError("The hp_max property may not be 0 for entities!");
if (prop->hp_max < sao->getHP()) {
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP_MAX);