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

pull/564/head
Loïc Guilloux 1 year ago committed by GitHub
parent 0cbbfd3eae
commit 8d2a0a7da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save