Permalink
Browse files

Fix crash in CloneArray for too large arrays (#566)

If there is not enough memory to clone an array, throw an error instead
of crashing the server.
  • Loading branch information...
1 parent d3d16a9 commit b74573fa125ce55ab109f13cc431b59f5be5d1e6 @peace-maker peace-maker committed with KyleSanderson Dec 12, 2016
Showing with 10 additions and 0 deletions.
  1. +6 −0 core/logic/CellArray.h
  2. +4 −0 core/logic/smn_adt_array.cpp
@@ -186,6 +186,12 @@ class CellArray : public ICellArray
array->m_AllocSize = m_AllocSize;
array->m_Size = m_Size;
array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
+ if (!array->m_Data)
+ {
+ delete array;
+ return NULL;
+ }
+
memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size);
return array;
}
@@ -503,6 +503,10 @@ static cell_t CloneArray(IPluginContext *pContext, const cell_t *params)
}
ICellArray *array = oldArray->clone();
+ if (!array)
+ {
+ return pContext->ThrowNativeError("Failed to clone array. Out of memory.");
+ }
Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL);
if (!hndl)

0 comments on commit b74573f

Please sign in to comment.