summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 01:06:22 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 01:06:22 (GMT)
commit306f0100f34c0f5461203065bbe2239a5a325ad6 (patch)
tree015731992c0e6895663b775e356792fffb76ff72
parent93b5513cf1d6ed328bbf2e90377fee7a487b545d (diff)
downloadcpython-306f0100f34c0f5461203065bbe2239a5a325ad6.zip
cpython-306f0100f34c0f5461203065bbe2239a5a325ad6.tar.gz
cpython-306f0100f34c0f5461203065bbe2239a5a325ad6.tar.bz2
Issue #6697: Fix a crash if sys.stdin or sys.stdout encoding contain a surrogate
This is *very* unlikely :-)
-rw-r--r--Python/bltinmodule.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index a658f9b..e1f2931 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1610,6 +1610,7 @@ builtin_input(PyObject *self, PyObject *args)
char *prompt;
char *s;
PyObject *stdin_encoding;
+ char *stdin_encoding_str;
PyObject *result;
stdin_encoding = PyObject_GetAttrString(fin, "encoding");
@@ -1617,6 +1618,11 @@ builtin_input(PyObject *self, PyObject *args)
/* stdin is a text stream, so it must have an
encoding. */
return NULL;
+ stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
+ if (stdin_encoding_str == NULL) {
+ Py_DECREF(stdin_encoding);
+ return NULL;
+ }
tmp = PyObject_CallMethod(fout, "flush", "");
if (tmp == NULL)
PyErr_Clear();
@@ -1625,12 +1631,18 @@ builtin_input(PyObject *self, PyObject *args)
if (promptarg != NULL) {
PyObject *stringpo;
PyObject *stdout_encoding;
- stdout_encoding = PyObject_GetAttrString(fout,
- "encoding");
+ char *stdout_encoding_str;
+ stdout_encoding = PyObject_GetAttrString(fout, "encoding");
if (stdout_encoding == NULL) {
Py_DECREF(stdin_encoding);
return NULL;
}
+ stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
+ if (stdout_encoding_str == NULL) {
+ Py_DECREF(stdin_encoding);
+ Py_DECREF(stdout_encoding);
+ return NULL;
+ }
stringpo = PyObject_Str(promptarg);
if (stringpo == NULL) {
Py_DECREF(stdin_encoding);
@@ -1638,7 +1650,7 @@ builtin_input(PyObject *self, PyObject *args)
return NULL;
}
po = PyUnicode_AsEncodedString(stringpo,
- _PyUnicode_AsString(stdout_encoding), NULL);
+ stdout_encoding_str, NULL);
Py_DECREF(stdout_encoding);
Py_DECREF(stringpo);
if (po == NULL) {
@@ -1676,10 +1688,7 @@ builtin_input(PyObject *self, PyObject *args)
result = NULL;
}
else {
- result = PyUnicode_Decode
- (s, len-1,
- _PyUnicode_AsString(stdin_encoding),
- NULL);
+ result = PyUnicode_Decode(s, len-1, stdin_encoding_str, NULL);
}
}
Py_DECREF(stdin_encoding);