diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2007-11-01 21:08:14 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2007-11-01 21:08:14 (GMT) |
commit | aae141a7513bb6ff44834f9a2459632d7a5f6b00 (patch) | |
tree | 72d98580a040674876bdb2919f2ac950e967e9b0 /Modules/_bsddb.c | |
parent | 744b32a544bae1bd4e40730802103ae823f3c673 (diff) | |
download | cpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.zip cpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.tar.gz cpython-aae141a7513bb6ff44834f9a2459632d7a5f6b00.tar.bz2 |
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.
Diffstat (limited to 'Modules/_bsddb.c')
-rw-r--r-- | Modules/_bsddb.c | 8 |
1 files changed, 7 insertions, 1 deletions
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 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags) * 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 @@ DL_EXPORT(void) init_bsddb(void) 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); |