Fix a potential crash in ArrayClone for too large arrays (#408)
This commit is contained in:
parent
828e74e6c3
commit
074af44ead
|
@ -99,7 +99,15 @@ static cell AMX_NATIVE_CALL ArrayClone(AMX* amx, cell* params)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return ArrayHandles.clone(vec->clone());
|
||||
auto data = vec->clone();
|
||||
|
||||
if (!data)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Failed to clone array. Out of memory.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ArrayHandles.clone(data);
|
||||
}
|
||||
|
||||
// native ArrayGetArray(Array:which, item, any:output[], size = -1);
|
||||
|
|
|
@ -135,6 +135,13 @@ public:
|
|||
array->m_AllocSize = m_AllocSize;
|
||||
array->m_Size = m_Size;
|
||||
array->m_Data = (cell *)malloc(sizeof(cell)* m_BlockSize * m_AllocSize);
|
||||
|
||||
if (!array->m_Data)
|
||||
{
|
||||
delete array;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
memcpy(array->m_Data, m_Data, sizeof(cell)* m_BlockSize * m_Size);
|
||||
return array;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user