Commit aa187c68 authored by Benjamin Peterson's avatar Benjamin Peterson

rewrite unpack_add_info, so it has less memory corruption bugs (closes #27944)

parent 118eb656
...@@ -36,6 +36,9 @@ Core and Builtins ...@@ -36,6 +36,9 @@ Core and Builtins
Library 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- - Issue #27934: Use ``float.__repr__`` instead of plain ``repr`` when JSON-
encoding an instance of a float subclass. Thanks Eddie James. encoding an instance of a float subclass. Thanks Eddie James.
......
...@@ -338,34 +338,33 @@ unpack_string(LogReaderObject *self, PyObject **pvalue) ...@@ -338,34 +338,33 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
static int static int
unpack_add_info(LogReaderObject *self) unpack_add_info(LogReaderObject *self)
{ {
PyObject *key; PyObject *key = NULL;
PyObject *value = NULL; PyObject *value = NULL;
int err; int err;
err = unpack_string(self, &key); err = unpack_string(self, &key);
if (!err) { if (err)
err = unpack_string(self, &value); goto finally;
if (err) err = unpack_string(self, &value);
Py_DECREF(key); if (err)
else { goto finally;
PyObject *list = PyDict_GetItem(self->info, key); PyObject *list = PyDict_GetItem(self->info, key);
if (list == NULL) { if (list == NULL) {
list = PyList_New(0); list = PyList_New(0);
if (list == NULL) { if (list == NULL) {
err = ERR_EXCEPTION; err = ERR_EXCEPTION;
goto finally; goto finally;
} }
if (PyDict_SetItem(self->info, key, list)) { if (PyDict_SetItem(self->info, key, list)) {
Py_DECREF(list); Py_DECREF(list);
err = ERR_EXCEPTION; err = ERR_EXCEPTION;
goto finally; goto finally;
}
Py_DECREF(list);
}
if (PyList_Append(list, value))
err = ERR_EXCEPTION;
} }
Py_DECREF(list);
} }
if (PyList_Append(list, value))
err = ERR_EXCEPTION;
finally: finally:
Py_XDECREF(key); Py_XDECREF(key);
Py_XDECREF(value); Py_XDECREF(value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment