Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python bug: null byte in input prompt

I've found that

input('some\x00 text')

will prompt for some instead of some text.

From sources, I've figured out that this function uses C function PyOS_Readline, which ignores everything in prompt after NULL byte.

From PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt):

fprintf(stderr, "%s", prompt);

https://github.com/python/cpython/blob/3.6/Python/bltinmodule.c#L1989 https://github.com/python/cpython/blob/3.6/Parser/myreadline.c#L251

Is this a bug or there is a reason for that?

Issue: http://bugs.python.org/issue30431

like image 564
Kostya Cholak Avatar asked May 22 '17 13:05

Kostya Cholak


1 Answers

The function signature pretty much requires a NUL terminated C-string, PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt), so there isn't much than can be done about this without changing the API and breaking interoperability with GNU readline.

like image 177
Raymond Hettinger Avatar answered Nov 17 '22 16:11

Raymond Hettinger