summaryrefslogtreecommitdiffstats
path: root/Modules/_bsddb.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-10-09 06:50:43 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-10-09 06:50:43 (GMT)
commit10bed54ae2cc7751ba944bc8a99b9ca0a690c06a (patch)
tree2e30614b07caccae82cc24ed359ce97620b29117 /Modules/_bsddb.c
parent392505391e1703fe0df4da8e077793f7e71b1075 (diff)
downloadcpython-10bed54ae2cc7751ba944bc8a99b9ca0a690c06a.zip
cpython-10bed54ae2cc7751ba944bc8a99b9ca0a690c06a.tar.gz
cpython-10bed54ae2cc7751ba944bc8a99b9ca0a690c06a.tar.bz2
Fix a double free when positioning a database cursor to a non-existant
string key (and probably a few other situations with string keys). This was reported with a patch as pybsddb sourceforge bug 1708868 by jjjhhhlll at gmail.
Diffstat (limited to 'Modules/_bsddb.c')
-rw-r--r--Modules/_bsddb.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index c840eaf..bc70cc3 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -328,7 +328,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);
}