[Python-checkins] r81322 - python/branches/py3k/Modules/_io/textio.c

victor.stinner python-checkins at python.org
Wed May 19 03:17:03 CEST 2010


Author: victor.stinner
Date: Wed May 19 03:17:01 2010
New Revision: 81322

Log:
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!).


Modified:
   python/branches/py3k/Modules/_io/textio.c

Modified: python/branches/py3k/Modules/_io/textio.c
==============================================================================
--- python/branches/py3k/Modules/_io/textio.c	(original)
+++ python/branches/py3k/Modules/_io/textio.c	Wed May 19 03:17:01 2010
@@ -905,8 +905,11 @@
                 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 @@
     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 @@
     Py_DECREF(res);
     if (r < 0)
         return NULL;
-    
+
     if (r > 0) {
         Py_RETURN_NONE; /* stream already closed */
     }


More information about the Python-checkins mailing list