diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-11 06:38:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 06:38:03 (GMT) |
commit | 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6 (patch) | |
tree | 5b7afcdceab6dae37e3db90f952c5c76fe46b5cf /Python | |
parent | bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d (diff) | |
download | cpython-8905fcc85a6fc3ac394bc89b0bbf40897e9497a6.zip cpython-8905fcc85a6fc3ac394bc89b0bbf40897e9497a6.tar.gz cpython-8905fcc85a6fc3ac394bc89b0bbf40897e9497a6.tar.bz2 |
bpo-35454: Fix miscellaneous minor issues in error handling. (#11077)
* bpo-35454: Fix miscellaneous minor issues in error handling.
* Fix a null pointer dereference.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 6 | ||||
-rw-r--r-- | Python/ceval.c | 2 | ||||
-rw-r--r-- | Python/codecs.c | 6 | ||||
-rw-r--r-- | Python/import.c | 4 | ||||
-rw-r--r-- | Python/pylifecycle.c | 6 |
5 files changed, 18 insertions, 6 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index ccbc73f..7eedd13 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -255,7 +255,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) diff --git a/Python/ceval.c b/Python/ceval.c index ebe1c50..de6ff29 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5109,7 +5109,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(); diff --git a/Python/codecs.c b/Python/codecs.c index 002fad30..ff2142d 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -129,8 +129,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); diff --git a/Python/import.c b/Python/import.c index 15637c6..c4f0877 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2143,10 +2143,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; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 6de32de..37ecc51 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1286,6 +1286,9 @@ new_interpreter(PyThreadState **tstate_p) PyDict_SetItemString(interp->sysdict, "modules", modules); _PySys_EndInit(interp->sysdict, interp); } + else if (PyErr_Occurred()) { + goto handle_error; + } bimod = _PyImport_FindBuiltin("builtins", modules); if (bimod != NULL) { @@ -1294,6 +1297,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); |