Fix ITS#1774, BDB keys need ulen and flags to be initialized because BDB

tries to retrieve both the key and the data.
This commit is contained in:
Howard Chu 2002-04-25 05:16:15 +00:00
parent c7262c7599
commit 43167d0fa6
3 changed files with 19 additions and 4 deletions

View File

@ -39,6 +39,8 @@ bdb_dn2id_add(
DBTzero( &key );
key.size = e->e_nname.bv_len + 2;
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
buf = ch_malloc( key.size );
key.data = buf;
buf[0] = DN_BASE_PREFIX;
@ -84,6 +86,7 @@ bdb_dn2id_add(
dnParent( &ptr, &pdn );
key.size = pdn.bv_len + 2;
key.ulen = key.size;
pdn.bv_val[-1] = DN_ONE_PREFIX;
key.data = pdn.bv_val-1;
ptr = pdn;
@ -124,6 +127,7 @@ bdb_dn2id_add(
dnParent( &ptr, &pdn );
key.size = pdn.bv_len + 2;
key.ulen = key.size;
key.data = pdn.bv_val - 1;
ptr = pdn;
}
@ -189,7 +193,7 @@ bdb_dn2id_delete(
if( !be_issuffix( be, &ptr )) {
buf[0] = DN_SUBTREE_PREFIX;
rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
rc = db->del( db, txn, &key, 0 );
if( rc != 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
@ -206,6 +210,7 @@ bdb_dn2id_delete(
dnParent( &ptr, &pdn );
key.size = pdn.bv_len + 2;
key.ulen = key.size;
pdn.bv_val[-1] = DN_ONE_PREFIX;
key.data = pdn.bv_val - 1;
ptr = pdn;
@ -245,6 +250,7 @@ bdb_dn2id_delete(
dnParent( &ptr, &pdn );
key.size = pdn.bv_len + 2;
key.ulen = key.size;
key.data = pdn.bv_val - 1;
ptr = pdn;
}
@ -528,6 +534,8 @@ bdb_dn2idl(
DBTzero( &key );
key.size = dn->bv_len + 2;
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = prefix;
AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );

View File

@ -684,9 +684,12 @@ bdb_idl_delete_key(
if ( rc == 0 ) {
if ( tmp != 0 ) {
/* Not a range, just delete it */
data.data = &id;
rc = cursor->c_get( cursor, key, &data,
DB_GET_BOTH | DB_RMW );
if (tmp != id) {
/* position to correct item */
tmp = id;
rc = cursor->c_get( cursor, key, &data,
DB_GET_BOTH | DB_RMW );
}
if ( rc == 0 ) {
rc = cursor->c_del( cursor, 0 );
if ( rc != 0 ) {

View File

@ -38,6 +38,8 @@ bdb_key_read(
DBTzero( &key );
bv2DBT(k,&key);
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
rc = bdb_idl_fetch_key( be, db, txn, &key, ids );
@ -88,6 +90,8 @@ bdb_key_change(
DBTzero( &key );
bv2DBT(k,&key);
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
if (op == SLAP_INDEX_ADD_OP) {
/* Add values */