1
0
Fork 0

Fix #10846: [Squirrel] Ensure sqvector size does not overflow (#10848)

pull/10922/head
Loïc Guilloux 2023-05-20 16:43:22 +02:00
parent 4cc0c21182
commit 7969907116
1 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,9 @@
#ifndef _SQUTILS_H_
#define _SQUTILS_H_
#include "../../fmt/format.h"
#include "../../../script/script_fatalerror.hpp"
void *sq_vm_malloc(SQUnsignedInteger size);
void *sq_vm_realloc(void *p,SQUnsignedInteger oldsize,SQUnsignedInteger size);
void sq_vm_free(void *p,SQUnsignedInteger size);
@ -102,6 +105,10 @@ private:
void _realloc(SQUnsignedInteger newsize)
{
newsize = (newsize > 0)?newsize:4;
if (newsize > SIZE_MAX / sizeof(T)) {
std::string msg = fmt::format("cannot resize to {}", newsize);
throw Script_FatalError(msg);
}
_vals = (T*)SQ_REALLOC(_vals, _allocated * sizeof(T), newsize * sizeof(T));
_allocated = (size_t)newsize;
}