From f7e5c17e48ff5e56e577184f838dd83a2759848d Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 20 Jun 2020 10:33:46 -0700 Subject: [PATCH 1/3] Fix a possible MemoryError leak within zoneinfo. This was detected by coverity as a REVERSE_INULL issue. --- Modules/_zoneinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index e8b28319993a18d..9bd75ff7a8abc52 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -1622,7 +1622,7 @@ parse_abbr(const char *const p, PyObject **abbr) } *abbr = PyUnicode_FromStringAndSize(str_start, str_end - str_start); - if (abbr == NULL) { + if (*abbr == NULL) { return -1; } From 36aae1c7fee3dacf0c04d7be38a55f2b8339612b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:33:08 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst new file mode 100644 index 000000000000000..0439d82a50ad12c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-33-03.bpo-41056.gTH4Bq.rst @@ -0,0 +1 @@ +Fixed an instance where a MemoryError within the zoneinfo module might not be reported or not reported at its source. (found by Coverity) \ No newline at end of file From dd4652870b52caa807cdb1a45d5f6abc43073d46 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 20 Jun 2020 12:13:03 -0700 Subject: [PATCH 3/3] Move the NULL check before the pointer is used. Coverity CID 1464644 --- Modules/_zoneinfo.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 9bd75ff7a8abc52..a2883495fe7fddd 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -278,13 +278,11 @@ zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw) instance = PyObject_CallMethod(weak_cache, "setdefault", "OO", key, tmp); - ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; - Py_DECREF(tmp); - if (instance == NULL) { return NULL; } + ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE; } update_strong_cache(type, key, instance);