]> granicus.if.org Git - python/commitdiff
rewrite unpack_add_info, so it has less memory corruption bugs (closes #27944)
authorBenjamin Peterson <benjamin@python.org>
Mon, 5 Sep 2016 19:44:38 +0000 (12:44 -0700)
committerBenjamin Peterson <benjamin@python.org>
Mon, 5 Sep 2016 19:44:38 +0000 (12:44 -0700)
Misc/NEWS
Modules/_hotshot.c

index 9f2a32250df13b30c428d79f69c52664bc0d6175..3b07cc95a0f858e02ec5434597f8459efa7fbcb3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #27944: Fix some memory-corruption bugs in the log reading code of the
+  _hotshot module.
+
 - Issue #27934: Use ``float.__repr__`` instead of plain ``repr`` when JSON-
   encoding an instance of a float subclass. Thanks Eddie James.
 
index 9719cb76733be675c150af40da994c4a9296ad5b..da30f3bdc3247cfcd760e853ec4da8b7cd31a6e0 100644 (file)
@@ -338,34 +338,33 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
 static int
 unpack_add_info(LogReaderObject *self)
 {
-    PyObject *key;
+    PyObject *key = NULL;
     PyObject *value = NULL;
     int err;
 
     err = unpack_string(self, &key);
-    if (!err) {
-        err = unpack_string(self, &value);
-        if (err)
-            Py_DECREF(key);
-        else {
-            PyObject *list = PyDict_GetItem(self->info, key);
-            if (list == NULL) {
-                list = PyList_New(0);
-                if (list == NULL) {
-                    err = ERR_EXCEPTION;
-                    goto finally;
-                }
-                if (PyDict_SetItem(self->info, key, list)) {
-                    Py_DECREF(list);
-                    err = ERR_EXCEPTION;
-                    goto finally;
-                }
-                Py_DECREF(list);
-            }
-            if (PyList_Append(list, value))
-                err = ERR_EXCEPTION;
+    if (err)
+        goto finally;
+    err = unpack_string(self, &value);
+    if (err)
+        goto finally;
+    PyObject *list = PyDict_GetItem(self->info, key);
+    if (list == NULL) {
+        list = PyList_New(0);
+        if (list == NULL) {
+            err = ERR_EXCEPTION;
+            goto finally;
+        }
+        if (PyDict_SetItem(self->info, key, list)) {
+            Py_DECREF(list);
+            err = ERR_EXCEPTION;
+            goto finally;
         }
+        Py_DECREF(list);
     }
+    if (PyList_Append(list, value))
+        err = ERR_EXCEPTION;
+
  finally:
     Py_XDECREF(key);
     Py_XDECREF(value);