o = bdb_find_id_node(id, bdb->bi_tree);
rlen = be->be_suffix[0]->bv_len + 1;
nrlen = be->be_nsuffix[0]->bv_len + 1;
- for (n = o; n; n=n->i_parent) {
+ for (n = o; n && n->i_parent; n=n->i_parent) {
rlen += n->i_rdn->rdn.bv_len + 1;
nrlen += n->i_rdn->nrdn.bv_len + 1;
}
e->e_nname.bv_val = e->e_name.bv_val + rlen;
ptr = e->e_name.bv_val;
nptr = e->e_nname.bv_val;
- for (n = o; n; n=n->i_parent) {
+ for (n = o; n && n->i_parent; n=n->i_parent) {
ptr = slap_strcopy(ptr, n->i_rdn->rdn.bv_val);
*ptr++ = ',';
nptr = slap_strcopy(nptr, n->i_rdn->nrdn.bv_val);
}
ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
- ptr--;
- nptr--;
strcpy(ptr, be->be_suffix[0]->bv_val);
strcpy(nptr, be->be_nsuffix[0]->bv_val);
d->rdn.bv_val -= (long)d;
d->nrdn.bv_val -= (long)d;
- if (pdn) {
+ if (pdn->bv_len) {
bdb_dn2id(be, txn, pdn, &d->parent);
} else {
d->parent = 0;
}
send_ldap_result( conn, op, rc=LDAP_REFERRAL ,
- matched_dn->bv_val, text, refs, NULL );
+ matched_dn ? matched_dn->bv_val : NULL, text, refs, NULL );
- ber_bvecfree( refs );
- ber_bvfree( matched_dn );
+ if ( refs ) ber_bvecfree( refs );
+ if ( matched_dn ) ber_bvfree( matched_dn );
return rc;
}