]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
check for ee == NULL
[openldap] / servers / slapd / overlays / rwm.c
index 031f9f5d3c22ec18a094af944d392cf81322c2a0..ed9fbfa9bb20377093a0a18dfda2fcd3403357d1 100644 (file)
@@ -226,9 +226,7 @@ rwm_op_add( Operation *op, SlapReply *rs )
                {
                        int             j, last;
 
-                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
-                                       /* count values */ ;
-                       last--;
+                       last = (*ap)->a_numvals - 1;
                        for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
                                struct ldapmapping      *mapping = NULL;
 
@@ -245,6 +243,7 @@ rwm_op_add( Operation *op, SlapReply *rs )
                                                        (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
                                                }
                                                BER_BVZERO( &(*ap)->a_vals[ last ] );
+                                               (*ap)->a_numvals--;
                                                last--;
                                                j--;
                                        }
@@ -504,14 +503,10 @@ rwm_op_modify( Operation *op, SlapReply *rs )
        isupdate = be_shadow_update( op );
        for ( mlp = &op->orm_modlist; *mlp; ) {
                int                     is_oc = 0;
-               Modifications           *ml;
+               Modifications           *ml = *mlp;
                struct ldapmapping      *mapping = NULL;
 
-               /* duplicate the modlist */
-               ml = ch_malloc( sizeof( Modifications ));
-               *ml = **mlp;
-               *mlp = ml;
-
+               /* ml points to a temporary mod until needs duplication */
                if ( ml->sml_desc == slap_schema.si_ad_objectClass 
                                || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
                {
@@ -519,6 +514,15 @@ rwm_op_modify( Operation *op, SlapReply *rs )
 
                } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod  )
                {
+                       ml = ch_malloc( sizeof( Modifications ) );
+                       *ml = **mlp;
+                       if ( (*mlp)->sml_values ) {
+                               ber_bvarray_dup_x( &ml->sml_values, (*mlp)->sml_values, NULL );
+                               if ( (*mlp)->sml_nvalues ) {
+                                       ber_bvarray_dup_x( &ml->sml_nvalues, (*mlp)->sml_nvalues, NULL );
+                               }
+                       }
+                       *mlp = ml;
                        goto next_mod;
 
                } else {
@@ -533,6 +537,11 @@ rwm_op_modify( Operation *op, SlapReply *rs )
                        }
                }
 
+               /* duplicate the modlist */
+               ml = ch_malloc( sizeof( Modifications ));
+               *ml = **mlp;
+               *mlp = ml;
+
                if ( ml->sml_values != NULL ) {
                        int i, num;
                        struct berval *bva;
@@ -835,8 +844,11 @@ rwm_exop_passwd( Operation *op, SlapReply *rs )
        }
 
        if ( !BER_BVISNULL( &id ) ) {
+               char idNul = id.bv_val[id.bv_len];
+               id.bv_val[id.bv_len] = '\0';
                rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
                                &op->o_req_ndn, op->o_tmpmemctx );
+               id.bv_val[id.bv_len] = idNul;
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        rs->sr_text = "Invalid DN";
                        return rs->sr_err;
@@ -1044,9 +1056,8 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                                        mapping->m_dst_ad->ad_type->sat_equality->smr_normalize )
                                {
                                        int i = 0;
-                                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
-                                               /* just count */ ;
 
+                                       last = (*ap)->a_numvals;
                                        if ( last )
                                        {
                                                (*ap)->a_nvals = ch_malloc( (last+1) * sizeof(struct berval) );
@@ -1095,8 +1106,7 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                }
 
                if ( last == -1 ) { /* not yet counted */ 
-                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
-                               /* just count */ ;
+                       last = (*ap)->a_numvals;
                }
 
                if ( last == 0 ) {
@@ -1215,6 +1225,7 @@ cleanup_attr:;
                                        mod.sm_op = LDAP_MOD_ADD;
                                        mod.sm_desc = (*ap)->a_desc;
                                        mod.sm_type = mod.sm_desc->ad_cname;
+                                       mod.sm_numvals = (*tap)->a_numvals;
                                        mod.sm_values = (*tap)->a_vals;
                                        mod.sm_nvalues = (*tap)->a_nvals;