summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 01:17:01 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 01:17:01 (GMT)
commitf6c578328c419f25dea91425479a6ceeb891b04d (patch)
tree5b3cb3aaa49e7f6ccd827b41652829e970a79799
parent306f0100f34c0f5461203065bbe2239a5a325ad6 (diff)
downloadcpython-f6c578328c419f25dea91425479a6ceeb891b04d.zip
cpython-f6c578328c419f25dea91425479a6ceeb891b04d.tar.gz
cpython-f6c578328c419f25dea91425479a6ceeb891b04d.tar.bz2
Issue #6697: Check that _PyUnicode_AsString() result is not NULL in textio.c
The bug may occurs if locale.getpreferredencoding() returns an encoding with a surrogate (very unlikely!).
-rw-r--r--Modules/_io/textio.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index b039c2f..b659795 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -905,8 +905,11 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
Py_CLEAR(self->encoding);
}
}
- if (self->encoding != NULL)
+ if (self->encoding != NULL) {
encoding = _PyUnicode_AsString(self->encoding);
+ if (encoding == NULL)
+ goto error;
+ }
else if (encoding != NULL) {
self->encoding = PyUnicode_FromString(encoding);
if (self->encoding == NULL)
@@ -935,6 +938,8 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
self->writetranslate = (newline == NULL || newline[0] != '\0');
if (!self->readuniversal && self->readnl) {
self->writenl = _PyUnicode_AsString(self->readnl);
+ if (self->writenl == NULL)
+ goto error;
if (!strcmp(self->writenl, "\n"))
self->writenl = NULL;
}
@@ -2408,7 +2413,7 @@ textiowrapper_close(textio *self, PyObject *args)
Py_DECREF(res);
if (r < 0)
return NULL;
-
+
if (r > 0) {
Py_RETURN_NONE; /* stream already closed */
}