Skip to content

Commit

Permalink
FIX: make sure that console's input buffer is not growing over 2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 3, 2021
1 parent 84f17ae commit 19f86be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/os/host-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void Host_Repl() {
int input_len = 0;
REBYTE *input = OS_Make(input_max);

REBYTE *tmp;
REBYTE *line;
int line_len;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 19f86be

Please sign in to comment.