diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-19 00:34:15 +0000 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-19 00:34:15 +0000 |
commit | f6e4e2c2fa3e76a272ca41f744f0cc4e68b193e7 (patch) | |
tree | 940feb32e8c711f300181b9cd7b1117284881d74 /Python/pythonrun.c | |
parent | eccd1c0fb2d70544c806f4a262b173c3c53ff01d (diff) | |
download | cpython-f6e4e2c2fa3e76a272ca41f744f0cc4e68b193e7.tar.gz |
Issue #6697: Check that _PyUnicode_AsString() result is not NULL
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index d3981961ee..58388c22d9 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -138,8 +138,8 @@ add_flag(int flag, const char *envs) 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 @@ get_codeset(void) 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 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags 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) { |