[Python-checkins] [3.7] bpo-34492: Modules/main.c: Fix copy_wstrlist() (GH-8910) (GH-8922)

Victor Stinner webhook-mailer at python.org
Sat Aug 25 12:47:01 EDT 2018


https://github.com/python/cpython/commit/388bd4bd7622f6781260ed388f7c76b673adb0e1
commit: 388bd4bd7622f6781260ed388f7c76b673adb0e1
branch: 3.7
author: Alexey Izbyshev <izbyshev at ispras.ru>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-08-25T18:46:58+02:00
summary:

[3.7] bpo-34492: Modules/main.c: Fix copy_wstrlist() (GH-8910) (GH-8922)

* Add missing NULL check reported by Svace static analyzer.
* Fix clear_wstrlist() call on a wrong list.

(cherry picked from commit eb746dbae8b320758ee08f811316d7f283435cc0)

Co-authored-by: Alexey Izbyshev <izbyshev at ispras.ru>

files:
M Modules/main.c

diff --git a/Modules/main.c b/Modules/main.c
index f82bab2cb1b8..45148dc98391 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1236,10 +1236,13 @@ copy_wstrlist(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) {
-            clear_wstrlist(i, list);
+            clear_wstrlist(i, list_copy);
             return NULL;
         }
         list_copy[i] = arg;



More information about the Python-checkins mailing list