[Python-checkins] r81319 - python/branches/py3k/Python/pythonrun.c

victor.stinner python-checkins at python.org
Wed May 19 02:34:15 CEST 2010


Author: victor.stinner
Date: Wed May 19 02:34:15 2010
New Revision: 81319

Log:
Issue #6697: Check that _PyUnicode_AsString() result is not NULL


Modified:
   python/branches/py3k/Python/pythonrun.c

Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c	(original)
+++ python/branches/py3k/Python/pythonrun.c	Wed May 19 02:34:15 2010
@@ -138,8 +138,8 @@
 static char*
 get_codeset(void)
 {
-    char* codeset;
-    PyObject *codec, *name;
+    char* codeset, *name_str;
+    PyObject *codec, *name = NULL;
 
     codeset = nl_langinfo(CODESET);
     if (!codeset || codeset[0] == '\0')
@@ -154,12 +154,16 @@
     if (!name)
         goto error;
 
-    codeset = strdup(_PyUnicode_AsString(name));
+    name_str = _PyUnicode_AsString(name);
+    if (name == NULL)
+        goto error;
+    codeset = strdup(name_str);
     Py_DECREF(name);
     return codeset;
 
 error:
     Py_XDECREF(codec);
+    Py_XDECREF(name);
     return NULL;
 }
 #endif
@@ -1060,22 +1064,34 @@
         if (!oenc)
             return -1;
         enc = _PyUnicode_AsString(oenc);
+        if (enc == NULL)
+            return -1;
     }
     v = PySys_GetObject("ps1");
     if (v != NULL) {
         v = PyObject_Str(v);
         if (v == NULL)
             PyErr_Clear();
-        else if (PyUnicode_Check(v))
+        else if (PyUnicode_Check(v)) {
             ps1 = _PyUnicode_AsString(v);
+            if (ps1 == NULL) {
+                PyErr_Clear();
+                ps1 = "";
+            }
+        }
     }
     w = PySys_GetObject("ps2");
     if (w != NULL) {
         w = PyObject_Str(w);
         if (w == NULL)
             PyErr_Clear();
-        else if (PyUnicode_Check(w))
+        else if (PyUnicode_Check(w)) {
             ps2 = _PyUnicode_AsString(w);
+            if (ps2 == NULL) {
+                PyErr_Clear();
+                ps2 = "";
+            }
+        }
     }
     arena = PyArena_New();
     if (arena == NULL) {


More information about the Python-checkins mailing list