From 4883006071696043f95c8d108fa06c7c462fd452 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Thu, 15 Oct 2026 19:10:00 +0200 Subject: [PATCH] fix(weapon): Add sanity check for weapon slot index in WeaponSet::setWeaponLock. --- .../Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp | 5 +++++ .../Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp index 3d140d352e6..2597d553bbb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp @@ -1065,6 +1065,11 @@ Bool WeaponSet::setWeaponLock( WeaponSlotType weaponSlot, WeaponLockType lockTyp return false; } + if (static_cast(weaponSlot) >= ARRAY_SIZE(m_weapons)) + { + return false; + } + // Verify the asked for weapon exists , choose it, and then lock it as chosen until unlocked // the old code was just plain wrong. (look at it in perforce and you'll see...) if (m_weapons[weaponSlot] != nullptr) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp index aeafb6dd7ae..1fa309ee8a8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp @@ -1109,6 +1109,11 @@ Bool WeaponSet::setWeaponLock( WeaponSlotType weaponSlot, WeaponLockType lockTyp return false; } + if (static_cast(weaponSlot) >= ARRAY_SIZE(m_weapons)) + { + return false; + } + // Verify the asked for weapon exists , choose it, and then lock it as chosen until unlocked // the old code was just plain wrong. (look at it in perforce and you'll see...) if (m_weapons[weaponSlot] != nullptr)