ldap/servers/slapd/back-ldbm/backentry.c | 4 +
ldap/servers/slapd/back-ldbm/ldbm_modrdn.c | 29 +++++++-----
ldap/servers/slapd/modutil.c | 65 ++++++++++++++++++++++++++---
3 files changed, 81 insertions(+), 17 deletions(-)
New commits:
commit fdcc256473679ed749294ff6623c7fa91c8748e8
Author: Noriko Hosoi <nhosoi(a)dhcp-32-235.sjc.redhat.com>
Date: Tue Feb 28 18:45:16 2012 -0800
Minor bug fix introcuded by commit 69c9f3bf7dd9fe2cadd5eae0ab72ce218b78820e
Fix description:
. The case modrdn without newsuperior was not take care of.
If newparententry is NULL, set NULL to back-up original_
newparent. as well.
. Added NULL argument checking to backentry_dup and slapi_mods APIs.
diff --git a/ldap/servers/slapd/back-ldbm/backentry.c
b/ldap/servers/slapd/back-ldbm/backentry.c
index 9fe6fb6..52468ad 100644
--- a/ldap/servers/slapd/back-ldbm/backentry.c
+++ b/ldap/servers/slapd/back-ldbm/backentry.c
@@ -104,6 +104,10 @@ backentry_dup( struct backentry *e )
{
struct backentry *ec;
+ if (NULL == e) {
+ return NULL;
+ }
+
ec = (struct backentry *) slapi_ch_calloc( 1, sizeof(struct backentry) );
ec->ep_id = e->ep_id;
ec->ep_entry = slapi_entry_dup( e->ep_entry );
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
index 39e965f..a7f13b5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
@@ -717,7 +717,8 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
ldap_result_code= LDAP_OPERATIONS_ERROR;
goto error_return;
}
- if ( (original_newparent = backentry_dup( newparententry )) == NULL ) {
+ if ( newparententry &&
+ ((original_newparent = backentry_dup( newparententry )) == NULL) ) {
ldap_result_code= LDAP_OPERATIONS_ERROR;
goto error_return;
}
@@ -780,9 +781,13 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
}
backentry_free(&newparententry);
- slapi_pblock_set( pb, SLAPI_MODRDN_NEWPARENT_ENTRY,
original_newparent->ep_entry );
+ if (original_newparent) {
+ slapi_pblock_set( pb, SLAPI_MODRDN_NEWPARENT_ENTRY,
+ original_newparent->ep_entry );
+ }
newparententry = original_entry;
- if ( (original_entry = backentry_dup( newparententry )) == NULL ) {
+ if ( newparententry &&
+ ((original_entry = backentry_dup(newparententry)) == NULL) ) {
ldap_result_code= LDAP_OPERATIONS_ERROR;
goto error_return;
}
@@ -796,16 +801,16 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
goto error_return;
}
- /* stash the transaction */
- slapi_pblock_set(pb, SLAPI_TXN, (void *)txn.back_txn_txn);
+ /* stash the transaction */
+ slapi_pblock_set(pb, SLAPI_TXN, (void *)txn.back_txn_txn);
- /* call the transaction pre modrdn plugins just after creating the transaction */
- if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN))) {
- LDAPDebug1Arg( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN plugin "
- "returned error code %d\n", retval );
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- goto error_return;
- }
+ /* call the transaction pre modrdn plugins just after creating the transaction
*/
+ if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN))) {
+ LDAPDebug1Arg( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN plugin
"
+ "returned error code %d\n", retval );
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ goto error_return;
+ }
/*
* Update the indexes for the entry.
diff --git a/ldap/servers/slapd/modutil.c b/ldap/servers/slapd/modutil.c
index 18b7fb6..c9beb20 100644
--- a/ldap/servers/slapd/modutil.c
+++ b/ldap/servers/slapd/modutil.c
@@ -101,6 +101,9 @@ slapi_mods_new()
void
slapi_mods_init(Slapi_Mods *smods, int initCount)
{
+ if (NULL == smods) {
+ return;
+ }
memset (smods, 0, sizeof (*smods));
smods->free_mods = 1;
if (initCount > 0)
@@ -117,6 +120,9 @@ slapi_mods_init(Slapi_Mods *smods, int initCount)
void
slapi_mods_init_passin(Slapi_Mods *smods, LDAPMod **mods)
{
+ if (NULL == smods) {
+ return;
+ }
slapi_mods_init_byref(smods, mods);
smods->free_mods = 1;
}
@@ -128,6 +134,9 @@ slapi_mods_init_passin(Slapi_Mods *smods, LDAPMod **mods)
void
slapi_mods_init_byref(Slapi_Mods *smods, LDAPMod **mods)
{
+ if (NULL == smods) {
+ return;
+ }
memset (smods, 0, sizeof (*smods));
if(mods!=NULL)
{
@@ -144,14 +153,16 @@ slapi_mods_free(Slapi_Mods **smods)
{
slapi_mods_done(*smods);
slapi_ch_free ((void**)smods);
- *smods= NULL;
+
}
}
void
slapi_mods_done(Slapi_Mods *smods)
{
- PR_ASSERT(smods!=NULL);
+ if (NULL == smods) {
+ return;
+ }
if (smods->mods!=NULL)
{
if(smods->free_mods)
@@ -165,7 +176,11 @@ slapi_mods_done(Slapi_Mods *smods)
static void
slapi_mods_add_one_element(Slapi_Mods *smods)
{
- int need = smods->num_mods + 2;
+ int need;
+ if (NULL == smods) {
+ return;
+ }
+ need = smods->num_mods + 2;
if ( smods->num_elements == 0 )
{
PR_ASSERT(smods->mods==NULL);
@@ -189,7 +204,7 @@ slapi_mods_insert_at(Slapi_Mods *smods, LDAPMod *mod, int pos)
{
int i;
- if (NULL == mod) {
+ if ((NULL == smods) || (NULL == mod)) {
return;
}
slapi_mods_add_one_element(smods);
@@ -205,6 +220,9 @@ slapi_mods_insert_at(Slapi_Mods *smods, LDAPMod *mod, int pos)
void
slapi_mods_insert_smod_at(Slapi_Mods *smods, Slapi_Mod *smod, int pos)
{
+ if ((NULL == smods) || (NULL == smod)) {
+ return;
+ }
slapi_mods_insert_at (smods, smod->mod, pos);
}
@@ -214,6 +232,9 @@ slapi_mods_insert_smod_at(Slapi_Mods *smods, Slapi_Mod *smod, int
pos)
void
slapi_mods_insert_before(Slapi_Mods *smods, LDAPMod *mod)
{
+ if ((NULL == smods) || (NULL == mod)) {
+ return;
+ }
slapi_mods_insert_at(smods, mod, smods->iterator);
smods->iterator++;
}
@@ -221,6 +242,9 @@ slapi_mods_insert_before(Slapi_Mods *smods, LDAPMod *mod)
void
slapi_mods_insert_smod_before(Slapi_Mods *smods, Slapi_Mod *smod)
{
+ if ((NULL == smods) || (NULL == smod)) {
+ return;
+ }
slapi_mods_insert_before(smods, smod->mod);
}
@@ -230,6 +254,9 @@ slapi_mods_insert_smod_before(Slapi_Mods *smods, Slapi_Mod *smod)
void
slapi_mods_insert_after(Slapi_Mods *smods, LDAPMod *mod)
{
+ if ((NULL == smods) || (NULL == mod)) {
+ return;
+ }
slapi_mods_insert_at(smods, mod, smods->iterator+1);
}
@@ -262,6 +289,9 @@ slapi_mods_add_modbvps( Slapi_Mods *smods, int modtype, const char
*type, struct
{
LDAPMod *mod;
+ if (NULL == smods) {
+ return;
+ }
mod = (LDAPMod *) slapi_ch_malloc(sizeof(LDAPMod));
mod->mod_type = slapi_ch_strdup( type );
mod->mod_op = modtype | LDAP_MOD_BVALUES;
@@ -293,7 +323,11 @@ slapi_mods_add_modbvps( Slapi_Mods *smods, int modtype, const char
*type, struct
void
slapi_mods_add_mod_values( Slapi_Mods *smods, int modtype, const char *type, Slapi_Value
**va )
{
- LDAPMod *mod= (LDAPMod *) slapi_ch_malloc( sizeof(LDAPMod) );
+ LDAPMod *mod;
+ if (NULL == smods) {
+ return;
+ }
+ mod = (LDAPMod *) slapi_ch_malloc( sizeof(LDAPMod) );
mod->mod_type = slapi_ch_strdup( type );
mod->mod_op = modtype | LDAP_MOD_BVALUES;
mod->mod_bvalues= NULL;
@@ -309,6 +343,9 @@ slapi_mods_add( Slapi_Mods *smods, int modtype, const char *type,
unsigned long
{
struct berval bv;
struct berval *bvps[2];
+ if (NULL == smods) {
+ return;
+ }
if(len>0)
{
bv.bv_len= len;
@@ -336,12 +373,18 @@ slapi_mods_add_string( Slapi_Mods *smods, int modtype, const char
*type, const c
void
slapi_mods_remove(Slapi_Mods *smods)
{
+ if (NULL == smods) {
+ return;
+ }
smods->mods[smods->iterator]->mod_op= LDAP_MOD_IGNORE;
}
LDAPMod *
slapi_mods_get_first_mod(Slapi_Mods *smods)
{
+ if (NULL == smods) {
+ return NULL;
+ }
/* Reset the iterator in the mod structure */
smods->iterator= -1;
return slapi_mods_get_next_mod(smods);
@@ -350,6 +393,9 @@ slapi_mods_get_first_mod(Slapi_Mods *smods)
LDAPMod *
slapi_mods_get_next_mod(Slapi_Mods *smods)
{
+ if (NULL == smods) {
+ return NULL;
+ }
/* Move the iterator forward */
LDAPMod *r= NULL;
smods->iterator++;
@@ -370,6 +416,9 @@ slapi_mods_get_next_mod(Slapi_Mods *smods)
static void
mod2smod (LDAPMod *mod, Slapi_Mod *smod)
{
+ if ((NULL == smod) || (NULL == mod)){
+ return;
+ }
smod->mod = mod;
smod->iterator = 0;
smod->num_values = 0;
@@ -425,6 +474,9 @@ slapi_mods_get_next_smod(Slapi_Mods *smods, Slapi_Mod *smod)
void
slapi_mods_iterator_backone(Slapi_Mods *smods)
{
+ if (NULL == smods) {
+ return;
+ }
smods->iterator--;
}
@@ -479,6 +531,9 @@ pack_mods(LDAPMod ***modsp)
LDAPMod **
slapi_mods_get_ldapmods_byref(Slapi_Mods *smods)
{
+ if (NULL == smods) {
+ return NULL;
+ }
pack_mods(&smods->mods); /* XXXggood const gets in the way of this */
return smods->mods;
}