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
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.
......
......@@ -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);
......
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