Fix bug introduced in revision 58385. Database keys could no longer
have NULL bytes in them. Replace the errant strdup with a
malloc+memcpy. Adds a unit test for the correct behavior.
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index f9bc253..d03f72b 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -335,11 +335,13 @@
* 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));
+ key->data = malloc(PyString_GET_SIZE(keyobj));
if (key->data == NULL) {
PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
return 0;
}
+ memcpy(key->data, PyString_AS_STRING(keyobj),
+ PyString_GET_SIZE(keyobj));
key->flags = DB_DBT_REALLOC;
key->size = PyString_GET_SIZE(keyobj);
}
@@ -5795,6 +5797,10 @@
ADD_INT(d, DB_NOPANIC);
#endif
+#ifdef DB_REGISTER
+ ADD_INT(d, DB_REGISTER);
+#endif
+
#if (DBVER >= 42)
ADD_INT(d, DB_TIME_NOTGRANTED);
ADD_INT(d, DB_TXN_NOT_DURABLE);