mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
InventoryManager: Disallow resizing or deleting inventory lists that are in use (#13360)
Naive solution to prevent InventoryList UAF and OOB ItemStack access caused by shrink/clear operations on InventoryLists within callbacks of an inventory action. Co-authored-by: Desour <ds.desour@proton.me>
This commit is contained in:
parent
4158b72971
commit
0fb6dbab36
3 changed files with 54 additions and 0 deletions
|
@ -284,6 +284,24 @@ public:
|
|||
inline bool checkModified() const { return m_dirty; }
|
||||
inline void setModified(bool dirty = true) { m_dirty = dirty; }
|
||||
|
||||
// Problem: C++ keeps references to InventoryList and ItemStack indices
|
||||
// until a better solution is found, this serves as a guard to prevent side-effects
|
||||
struct ResizeUnlocker {
|
||||
void operator()(InventoryList *invlist)
|
||||
{
|
||||
invlist->m_resize_locks -= 1;
|
||||
}
|
||||
};
|
||||
using ResizeLocked = std::unique_ptr<InventoryList, ResizeUnlocker>;
|
||||
|
||||
void checkResizeLock();
|
||||
|
||||
inline ResizeLocked resizeLock()
|
||||
{
|
||||
m_resize_locks += 1;
|
||||
return ResizeLocked(this);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<ItemStack> m_items;
|
||||
std::string m_name;
|
||||
|
@ -291,6 +309,7 @@ private:
|
|||
u32 m_width = 0;
|
||||
IItemDefManager *m_itemdef;
|
||||
bool m_dirty = true;
|
||||
int m_resize_locks = 0; // Lua callback sanity
|
||||
};
|
||||
|
||||
class Inventory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue