shithub: rgbds

Download patch

ref: 542b5d18f1307f23104bdc52fed03ad249895c1c
parent: 71a0a42cfb482929834973fd206f5dcc1bdbdaae
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Aug 22 20:51:36 EDT 2020

Fix possible capture buffer size overflow

Attempt to grow it to the max size first.
Seriously, if this triggers, *how*

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -503,7 +503,12 @@
 
 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));