From f4fd90837a0f7b2c40e05fc883bba5b63afd0ecb Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 3 Apr 2023 06:25:35 +1000 Subject: [PATCH] Fix null ptr deref when starting map dfwc2017-6 Caused by 9b8502fe368052b4b81985084542548e6992cf72 which was needed for b95beb262077d8f733bbee7cb0d5f4c05b7b3e2f --- qcsrc/server/items/items.qc | 18 ++++++++++-------- qcsrc/server/items/items.qh | 2 -- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 6562e5753..9d53f7a28 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -949,12 +949,6 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default if(def.m_iteminit) def.m_iteminit(def, this); - if(!this.respawntime) // both need to be set - { - this.respawntime = defaultrespawntime; - this.respawntimejitter = defaultrespawntimejitter; - } - if(!this.pickup_anyway && def.m_pickupanyway) this.pickup_anyway = def.m_pickupanyway(); @@ -1017,6 +1011,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default } else { + // must be done after def.m_iteminit() as that may set ITEM_FLAG_MUTATORBLOCKED if(!have_pickup_item(this)) { startitem_failed = true; @@ -1024,6 +1019,13 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default return; } + // must be done before Item_Reset() and after MUTATORBLOCKED check (blocked items may have null func ptrs) + if(!this.respawntime) // both need to be set + { + this.respawntime = defaultrespawntime ? defaultrespawntime : def.m_respawntime(); + this.respawntimejitter = defaultrespawntimejitter ? defaultrespawntimejitter : def.m_respawntimejitter(); + } + if(this.angles != '0 0 0') this.SendFlags |= ISF_ANGLES; @@ -1173,8 +1175,8 @@ void StartItem(entity this, GameItem def) _StartItem( this, this.itemdef = def, - def.m_respawntime(), // defaultrespawntime - def.m_respawntimejitter() // defaultrespawntimejitter + 0, // call def.m_respawntime() to get defaultrespawntime + 0 // call def.m_respawntimejitter() to get defaultrespawntimejitter ); } diff --git a/qcsrc/server/items/items.qh b/qcsrc/server/items/items.qh index 95e27f836..8af67c8de 100644 --- a/qcsrc/server/items/items.qh +++ b/qcsrc/server/items/items.qh @@ -19,8 +19,6 @@ void StartItem(entity this, entity a); float autocvar_sv_simple_items; bool ItemSend(entity this, entity to, int sf); -bool have_pickup_item(entity this); - const float ITEM_RESPAWN_TICKS = 10; // string overrides entity -- 2.39.2