[Python-checkins] cpython (2.7): rewrite unpack_add_info, so it has less memory corruption bugs (closes #27944)
benjamin.peterson
python-checkins at python.org
Mon Sep 5 15:45:02 EDT 2016
https://hg.python.org/cpython/rev/aefdfa167f4b
changeset: 103056:aefdfa167f4b
branch: 2.7
parent: 103048:32552131d8cb
user: Benjamin Peterson <benjamin at python.org>
date: Mon Sep 05 12:44:38 2016 -0700
summary:
rewrite unpack_add_info, so it has less memory corruption bugs (closes #27944)
files:
Misc/NEWS | 3 ++
Modules/_hotshot.c | 43 ++++++++++++++++-----------------
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@
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.
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -338,34 +338,33 @@
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);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list