From 19f86be34a5dc6c521e8d14ac3587fbb0c192533 Mon Sep 17 00:00:00 2001 From: Oldes Date: Sat, 3 Apr 2021 12:31:01 +0200 Subject: [PATCH] FIX: make sure that console's input buffer is not growing over 2GB --- src/os/host-main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/os/host-main.c b/src/os/host-main.c index 34fdcaa416..621b98e2ab 100644 --- a/src/os/host-main.c +++ b/src/os/host-main.c @@ -117,6 +117,7 @@ void Host_Repl() { int input_len = 0; REBYTE *input = OS_Make(input_max); + REBYTE *tmp; REBYTE *line; int line_len; @@ -191,15 +192,19 @@ void Host_Repl() { inside_short_str = FALSE; if (input_len + line_len > input_max) { - REBYTE *tmp = OS_Make(2 * input_max); + // limit maximum input size to 2GB (it should be more than enough) + if (input_max >= 0x80000000) goto crash_buffer; + input_max *= 2; + tmp = OS_Make(input_max); if (!tmp) { + crash_buffer: Put_Str(b_cast("\x1B[0m")); //reset console color; Host_Crash("Growing console input buffer failed!"); + return; // make VS compiler happy } memcpy(tmp, input, input_len); OS_Free(input); input = tmp; - input_max *= 2; } memcpy(&input[input_len], line, line_len);