fix scanf buffer overflow

This commit is contained in:
blueloveTH 2024-09-28 12:18:59 +08:00
parent 7fff96dc61
commit 7967852eb9

View File

@ -184,10 +184,16 @@ static bool builtins_input(int argc, py_Ref argv) {
prompt = py_tostr(argv);
}
printf("%s", prompt);
char buf[2048];
scanf("%s", buf);
getchar();
py_newstr(py_retval(), buf);
c11_sbuf buf;
c11_sbuf__ctor(&buf);
while(true) {
int c = getchar();
if(c == '\n') break;
if(c == EOF) break;
c11_sbuf__write_char(&buf, c);
}
c11_sbuf__py_submit(&buf, py_retval());
return true;
}