From ff12462f32487f2dab80034bcbaceb0d537cf25f Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Sat, 25 Aug 2018 01:35:58 +0300 Subject: [PATCH 1/2] bpo-34492: Python/coreconfig.c: Add missing NULL check to _Py_wstrlist_copy() Reported by Svace static analyzer. --- Python/coreconfig.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 1a32525b7b319b..0c6bda9d89ecd9 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -69,6 +69,9 @@ _Py_wstrlist_copy(int len, wchar_t **list) assert((len > 0 && list != NULL) || len == 0); size_t size = len * sizeof(list[0]); wchar_t **list_copy = PyMem_RawMalloc(size); + if (list_copy == NULL) { + return NULL; + } for (int i=0; i < len; i++) { wchar_t* arg = _PyMem_RawWcsdup(list[i]); if (arg == NULL) { From 6e5c32db9f88a61108585b5b806e4f1c03434811 Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Sat, 25 Aug 2018 01:49:48 +0300 Subject: [PATCH 2/2] Fix _Py_wstrlist_clear() call on a wrong list --- Python/coreconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 0c6bda9d89ecd9..1b9e26e50a2b23 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -75,7 +75,7 @@ _Py_wstrlist_copy(int len, wchar_t **list) for (int i=0; i < len; i++) { wchar_t* arg = _PyMem_RawWcsdup(list[i]); if (arg == NULL) { - _Py_wstrlist_clear(i, list); + _Py_wstrlist_clear(i, list_copy); return NULL; } list_copy[i] = arg;