1
0

cItems: Added runtime bounds-checking to avoid server crashes with badly written plugins.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1472 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2013-05-12 15:58:29 +00:00
parent 8f2920a090
commit 25cda4e8b4
4 changed files with 103 additions and 89 deletions

View File

@@ -138,3 +138,62 @@ bool cItem::IsEnchantable(short item)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cItems:
cItem * cItems::Get(int a_Idx)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %d items. Returning a nil.", a_Idx, size());
return NULL;
}
return &at(a_Idx);
}
void cItems::Set(int a_Idx, const cItem & a_Item)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size());
return;
}
at(a_Idx) = a_Item;
}
void cItems::Delete(int a_Idx)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %d items. Ignoring.", a_Idx, size());
return;
}
erase(begin() + a_Idx);
}
void cItems::Set(int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage)
{
if ((a_Idx < 0) || (a_Idx >= (int)size()))
{
LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size());
return;
}
at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);
}