Fix possible capture buffer size overflow

Attempt to grow it to the max size first.
Seriously, if this triggers, *how*
This commit is contained in:
ISSOtm
2020-08-23 00:51:36 +02:00
parent 71a0a42cfb
commit 542b5d18f1

View File

@@ -503,7 +503,12 @@ void lexer_ToggleStringExpansion(bool enable)
static void reallocCaptureBuf(void)
{
lexerState->captureCapacity *= 2;
if (lexerState->captureCapacity == SIZE_MAX)
fatalerror("Cannot grow capture buffer past %zu bytes", SIZE_MAX);
else if (lexerState->captureCapacity > SIZE_MAX / 2)
lexerState->captureCapacity = SIZE_MAX;
else
lexerState->captureCapacity *= 2;
lexerState->captureBuf = realloc(lexerState->captureBuf, lexerState->captureCapacity);
if (!lexerState->captureBuf)
fatalerror("realloc error while resizing capture buffer: %s\n", strerror(errno));