Skip to content

Commit 19f86be

Browse files
committed
FIX: make sure that console's input buffer is not growing over 2GB
1 parent 84f17ae commit 19f86be

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/os/host-main.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void Host_Repl() {
117117
int input_len = 0;
118118
REBYTE *input = OS_Make(input_max);
119119

120+
REBYTE *tmp;
120121
REBYTE *line;
121122
int line_len;
122123

@@ -191,15 +192,19 @@ void Host_Repl() {
191192
inside_short_str = FALSE;
192193

193194
if (input_len + line_len > input_max) {
194-
REBYTE *tmp = OS_Make(2 * input_max);
195+
// limit maximum input size to 2GB (it should be more than enough)
196+
if (input_max >= 0x80000000) goto crash_buffer;
197+
input_max *= 2;
198+
tmp = OS_Make(input_max);
195199
if (!tmp) {
200+
crash_buffer:
196201
Put_Str(b_cast("\x1B[0m")); //reset console color;
197202
Host_Crash("Growing console input buffer failed!");
203+
return; // make VS compiler happy
198204
}
199205
memcpy(tmp, input, input_len);
200206
OS_Free(input);
201207
input = tmp;
202-
input_max *= 2;
203208
}
204209

205210
memcpy(&input[input_len], line, line_len);

0 commit comments

Comments
 (0)