summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-10-09 07:25:24 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-10-09 07:25:24 (GMT)
commit7d9c00ec4f8f8347c91fd60ae4eab032e385234b (patch)
tree5b2419948a480b94c376bab819a3db2dff6a8bcc /Modules
parent381e1a46cd782bc2090c3f718b34682e06380bbd (diff)
downloadcpython-7d9c00ec4f8f8347c91fd60ae4eab032e385234b.zip
cpython-7d9c00ec4f8f8347c91fd60ae4eab032e385234b.tar.gz
cpython-7d9c00ec4f8f8347c91fd60ae4eab032e385234b.tar.bz2
Backport 58385 from trunk: fix a double free bug in the _bsddb module
on DBCursor.get (and a friends) when passing in a string key.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index 7b31054..195132e 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -425,7 +425,19 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags)
return 0;
}
- key->data = PyString_AS_STRING(keyobj);
+ /*
+ * NOTE(gps): I don't like doing a data copy here, it seems
+ * wasteful. But without a clean way to tell FREE_DBT if it
+ * should free key->data or not we have to. Other places in
+ * the code check for DB_THREAD and forceably set DBT_MALLOC
+ * when we otherwise would leave flags 0 to indicate that.
+ */
+ key->data = strdup(PyString_AS_STRING(keyobj));
+ if (key->data == NULL) {
+ PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
+ return 0;
+ }
+ key->flags = DB_DBT_REALLOC;
key->size = PyString_GET_SIZE(keyobj);
}