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

This commit is contained in:
Victor Stinner 2010-05-19 00:34:15 +00:00
parent f3f22a278d
commit 386fe71de1
1 changed files with 21 additions and 5 deletions

View File

@ -138,8 +138,8 @@ add_flag(int flag, const char *envs)
static char* static char*
get_codeset(void) get_codeset(void)
{ {
char* codeset; char* codeset, *name_str;
PyObject *codec, *name; PyObject *codec, *name = NULL;
codeset = nl_langinfo(CODESET); codeset = nl_langinfo(CODESET);
if (!codeset || codeset[0] == '\0') if (!codeset || codeset[0] == '\0')
@ -154,12 +154,16 @@ get_codeset(void)
if (!name) if (!name)
goto error; goto error;
codeset = strdup(_PyUnicode_AsString(name)); name_str = _PyUnicode_AsString(name);
if (name == NULL)
goto error;
codeset = strdup(name_str);
Py_DECREF(name); Py_DECREF(name);
return codeset; return codeset;
error: error:
Py_XDECREF(codec); Py_XDECREF(codec);
Py_XDECREF(name);
return NULL; return NULL;
} }
#endif #endif
@ -1060,22 +1064,34 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
if (!oenc) if (!oenc)
return -1; return -1;
enc = _PyUnicode_AsString(oenc); enc = _PyUnicode_AsString(oenc);
if (enc == NULL)
return -1;
} }
v = PySys_GetObject("ps1"); v = PySys_GetObject("ps1");
if (v != NULL) { if (v != NULL) {
v = PyObject_Str(v); v = PyObject_Str(v);
if (v == NULL) if (v == NULL)
PyErr_Clear(); PyErr_Clear();
else if (PyUnicode_Check(v)) else if (PyUnicode_Check(v)) {
ps1 = _PyUnicode_AsString(v); ps1 = _PyUnicode_AsString(v);
if (ps1 == NULL) {
PyErr_Clear();
ps1 = "";
}
}
} }
w = PySys_GetObject("ps2"); w = PySys_GetObject("ps2");
if (w != NULL) { if (w != NULL) {
w = PyObject_Str(w); w = PyObject_Str(w);
if (w == NULL) if (w == NULL)
PyErr_Clear(); PyErr_Clear();
else if (PyUnicode_Check(w)) else if (PyUnicode_Check(w)) {
ps2 = _PyUnicode_AsString(w); ps2 = _PyUnicode_AsString(w);
if (ps2 == NULL) {
PyErr_Clear();
ps2 = "";
}
}
} }
arena = PyArena_New(); arena = PyArena_New();
if (arena == NULL) { if (arena == NULL) {