mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix scanf
buffer overflow
This commit is contained in:
parent
7fff96dc61
commit
7967852eb9
@ -184,10 +184,16 @@ static bool builtins_input(int argc, py_Ref argv) {
|
|||||||
prompt = py_tostr(argv);
|
prompt = py_tostr(argv);
|
||||||
}
|
}
|
||||||
printf("%s", prompt);
|
printf("%s", prompt);
|
||||||
char buf[2048];
|
|
||||||
scanf("%s", buf);
|
c11_sbuf buf;
|
||||||
getchar();
|
c11_sbuf__ctor(&buf);
|
||||||
py_newstr(py_retval(), 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user