Changeset - r27397:3e6635e1d042
[Not reviewed]
master
0 1 0
Loïc Guilloux - 15 months ago 2023-05-20 14:43:22
glx22@users.noreply.github.com
Fix #10846: [Squirrel] Ensure sqvector size does not overflow (#10848)
1 file changed with 7 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/3rdparty/squirrel/squirrel/squtils.h
Show inline comments
 
@@ -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;
 
	}
0 comments (0 inline, 0 general)