summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-11 11:17:48 (GMT)
committerGitHub <noreply@github.com>2023-06-11 11:17:48 (GMT)
commit122a1a2629f6d3f39c7f473bc96aa3b5d834c49f (patch)
treefe166e17fff417399f4b0f4db645c0fe93694abe /Python
parentb4b5565e4779d81c943bffe22ffe0972fa398702 (diff)
downloadcpython-122a1a2629f6d3f39c7f473bc96aa3b5d834c49f.zip
cpython-122a1a2629f6d3f39c7f473bc96aa3b5d834c49f.tar.gz
cpython-122a1a2629f6d3f39c7f473bc96aa3b5d834c49f.tar.bz2
[3.12] gh-105375: Improve error handling in the builtins extension module (GH-105585) (#105649)
(cherry picked from commit d4fa52934a282df51cff800eee5caeb94a229547) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index ddddc03..45ce3b7 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2164,17 +2164,29 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
/* stdin is a text stream, so it must have an encoding. */
stdin_encoding = PyObject_GetAttr(fin, &_Py_ID(encoding));
+ if (stdin_encoding == NULL) {
+ tty = 0;
+ goto _readline_errors;
+ }
stdin_errors = PyObject_GetAttr(fin, &_Py_ID(errors));
- if (!stdin_encoding || !stdin_errors ||
- !PyUnicode_Check(stdin_encoding) ||
- !PyUnicode_Check(stdin_errors)) {
+ if (stdin_errors == NULL) {
+ tty = 0;
+ goto _readline_errors;
+ }
+ if (!PyUnicode_Check(stdin_encoding) ||
+ !PyUnicode_Check(stdin_errors))
+ {
tty = 0;
goto _readline_errors;
}
stdin_encoding_str = PyUnicode_AsUTF8(stdin_encoding);
+ if (stdin_encoding_str == NULL) {
+ goto _readline_errors;
+ }
stdin_errors_str = PyUnicode_AsUTF8(stdin_errors);
- if (!stdin_encoding_str || !stdin_errors_str)
+ if (stdin_errors_str == NULL) {
goto _readline_errors;
+ }
tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
if (tmp == NULL)
PyErr_Clear();
@@ -2185,17 +2197,29 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
const char *stdout_encoding_str, *stdout_errors_str;
PyObject *stringpo;
stdout_encoding = PyObject_GetAttr(fout, &_Py_ID(encoding));
+ if (stdout_encoding == NULL) {
+ tty = 0;
+ goto _readline_errors;
+ }
stdout_errors = PyObject_GetAttr(fout, &_Py_ID(errors));
- if (!stdout_encoding || !stdout_errors ||
- !PyUnicode_Check(stdout_encoding) ||
- !PyUnicode_Check(stdout_errors)) {
+ if (stdout_errors == NULL) {
+ tty = 0;
+ goto _readline_errors;
+ }
+ if (!PyUnicode_Check(stdout_encoding) ||
+ !PyUnicode_Check(stdout_errors))
+ {
tty = 0;
goto _readline_errors;
}
stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding);
+ if (stdout_encoding_str == NULL) {
+ goto _readline_errors;
+ }
stdout_errors_str = PyUnicode_AsUTF8(stdout_errors);
- if (!stdout_encoding_str || !stdout_errors_str)
+ if (stdout_errors_str == NULL) {
goto _readline_errors;
+ }
stringpo = PyObject_Str(prompt);
if (stringpo == NULL)
goto _readline_errors;