Fix a potential crash in ArrayClone for too large arrays (#408)

This commit is contained in:
Vincent Herbet 2017-02-23 13:27:16 +01:00 committed by GitHub
parent 828e74e6c3
commit 074af44ead
2 changed files with 16 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}