mirror of
https://github.com/python/cpython.git
synced 2025-10-05 06:31:48 +00:00
[3.5] bpo-8256: Fixed possible failing or crashing input() (#642)
if attributes "encoding" or "errors" of sys.stdin or sys.stdout
are not set or are not strings.
(cherry picked from commit c2cf128571
)
This commit is contained in:
parent
a6aac8c870
commit
a16894ebf8
2 changed files with 19 additions and 5 deletions
|
@ -41,6 +41,9 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-8256: Fixed possible failing or crashing input() if attributes "encoding"
|
||||||
|
or "errors" of sys.stdin or sys.stdout are not set or are not strings.
|
||||||
|
|
||||||
- bpo-28298: Fix a bug that prevented array 'Q', 'L' and 'I' from accepting big
|
- bpo-28298: Fix a bug that prevented array 'Q', 'L' and 'I' from accepting big
|
||||||
intables (objects that have __int__) as elements. Patch by Oren Milman.
|
intables (objects that have __int__) as elements. Patch by Oren Milman.
|
||||||
|
|
||||||
|
|
|
@ -1892,12 +1892,15 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
/* stdin is a text stream, so it must have an encoding. */
|
||||||
stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding);
|
stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding);
|
||||||
stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors);
|
stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors);
|
||||||
if (!stdin_encoding || !stdin_errors)
|
if (!stdin_encoding || !stdin_errors ||
|
||||||
/* stdin is a text stream, so it must have an
|
!PyUnicode_Check(stdin_encoding) ||
|
||||||
encoding. */
|
!PyUnicode_Check(stdin_errors)) {
|
||||||
|
tty = 0;
|
||||||
goto _readline_errors;
|
goto _readline_errors;
|
||||||
|
}
|
||||||
stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
|
stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
|
||||||
stdin_errors_str = _PyUnicode_AsString(stdin_errors);
|
stdin_errors_str = _PyUnicode_AsString(stdin_errors);
|
||||||
if (!stdin_encoding_str || !stdin_errors_str)
|
if (!stdin_encoding_str || !stdin_errors_str)
|
||||||
|
@ -1913,8 +1916,12 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
||||||
PyObject *stringpo;
|
PyObject *stringpo;
|
||||||
stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
|
stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
|
||||||
stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors);
|
stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors);
|
||||||
if (!stdout_encoding || !stdout_errors)
|
if (!stdout_encoding || !stdout_errors ||
|
||||||
|
!PyUnicode_Check(stdout_encoding) ||
|
||||||
|
!PyUnicode_Check(stdout_errors)) {
|
||||||
|
tty = 0;
|
||||||
goto _readline_errors;
|
goto _readline_errors;
|
||||||
|
}
|
||||||
stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
|
stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
|
||||||
stdout_errors_str = _PyUnicode_AsString(stdout_errors);
|
stdout_errors_str = _PyUnicode_AsString(stdout_errors);
|
||||||
if (!stdout_encoding_str || !stdout_errors_str)
|
if (!stdout_encoding_str || !stdout_errors_str)
|
||||||
|
@ -1969,13 +1976,17 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
|
||||||
Py_XDECREF(po);
|
Py_XDECREF(po);
|
||||||
PyMem_FREE(s);
|
PyMem_FREE(s);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
_readline_errors:
|
_readline_errors:
|
||||||
Py_XDECREF(stdin_encoding);
|
Py_XDECREF(stdin_encoding);
|
||||||
Py_XDECREF(stdout_encoding);
|
Py_XDECREF(stdout_encoding);
|
||||||
Py_XDECREF(stdin_errors);
|
Py_XDECREF(stdin_errors);
|
||||||
Py_XDECREF(stdout_errors);
|
Py_XDECREF(stdout_errors);
|
||||||
Py_XDECREF(po);
|
Py_XDECREF(po);
|
||||||
|
if (tty)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fallback if we're not interactive */
|
/* Fallback if we're not interactive */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue