bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077)

* bpo-35454: Fix miscellaneous minor issues in error handling.

* Fix a null pointer dereference.
(cherry picked from commit 8905fcc85a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-12-10 23:05:13 -08:00 committed by GitHub
parent 3b9a0186c4
commit 62674f3a36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 23 deletions

View file

@ -256,7 +256,11 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
version_obj = _PyDict_GetItemId(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != _PyRuntime.warnings.filters_version) {
|| PyLong_AsLong(version_obj) != _PyRuntime.warnings.filters_version)
{
if (PyErr_Occurred()) {
return -1;
}
PyDict_Clear(registry);
version_obj = PyLong_FromLong(_PyRuntime.warnings.filters_version);
if (version_obj == NULL)

View file

@ -5027,7 +5027,7 @@ unicode_concatenate(PyObject *v, PyObject *w,
PyObject *names = f->f_code->co_names;
PyObject *name = GETITEM(names, oparg);
PyObject *locals = f->f_locals;
if (PyDict_CheckExact(locals) &&
if (locals && PyDict_CheckExact(locals) &&
PyDict_GetItem(locals, name) == v) {
if (PyDict_DelItem(locals, name) != 0) {
PyErr_Clear();

View file

@ -130,8 +130,10 @@ PyObject *_PyCodec_Lookup(const char *encoding)
/* Next, scan the search functions in order of registration */
args = PyTuple_New(1);
if (args == NULL)
goto onError;
if (args == NULL) {
Py_DECREF(v);
return NULL;
}
PyTuple_SET_ITEM(args,0,v);
len = PyList_Size(interp->codec_search_path);

View file

@ -2138,10 +2138,10 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
}
mod = _PyImport_FindExtensionObject(name, path);
if (mod != NULL) {
if (mod != NULL || PyErr_Occurred()) {
Py_DECREF(name);
Py_DECREF(path);
Py_INCREF(mod);
Py_XINCREF(mod);
return mod;
}

View file

@ -1417,6 +1417,9 @@ new_interpreter(PyThreadState **tstate_p)
PyDict_SetItemString(interp->sysdict, "modules", modules);
_PySys_EndInit(interp->sysdict, &interp->config);
}
else if (PyErr_Occurred()) {
goto handle_error;
}
bimod = _PyImport_FindBuiltin("builtins", modules);
if (bimod != NULL) {
@ -1425,6 +1428,9 @@ new_interpreter(PyThreadState **tstate_p)
goto handle_error;
Py_INCREF(interp->builtins);
}
else if (PyErr_Occurred()) {
goto handle_error;
}
/* initialize builtin exceptions */
_PyExc_Init(bimod);