]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10067 Account for mods being optional
authorOndřej Kuzník <ondra@mistotebe.net>
Mon, 19 Jun 2023 14:41:09 +0000 (15:41 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 31 Jul 2023 18:07:17 +0000 (18:07 +0000)
servers/slapd/back-asyncmeta/modify.c
servers/slapd/back-meta/modify.c

index a70bae82e3143cc37d443b994cc64f15fcbf2ba2..c28bdc48e50f43b5de9227766ae78ed3bb92669f 100644 (file)
@@ -67,21 +67,15 @@ asyncmeta_back_modify_start(Operation *op,
 
        for ( i = 0, ml = op->orm_modlist; ml; i++ ,ml = ml->sml_next )
                ;
-       if (i > 0) {
-               mods = op->o_tmpalloc( sizeof( LDAPMod )*i, op->o_tmpmemctx );
-       }
 
-       if ( mods == NULL ) {
-               rs->sr_err = LDAP_OTHER;
-               retcode = META_SEARCH_ERR;
-               goto doreturn;
-       }
-       modv = ( LDAPMod ** )op->o_tmpalloc( ( i + 1 )*sizeof( LDAPMod * ), op->o_tmpmemctx );
+       modv = op->o_tmpalloc( ( i + 1 )*sizeof( LDAPMod * ) + i*sizeof( LDAPMod ),
+                       op->o_tmpmemctx );
        if ( modv == NULL ) {
                rs->sr_err = LDAP_OTHER;
                retcode = META_SEARCH_ERR;
                goto doreturn;
        }
+       mods = (LDAPMod *)&modv[ i + 1 ];
 
        isupdate = be_shadow_update( op );
        for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
@@ -224,6 +218,8 @@ done:
                op->o_tmpfree( mdn.bv_val, op->o_tmpmemctx );
        }
 
+       op->o_tmpfree( modv, op->o_tmpmemctx );
+
 doreturn:;
        Debug( LDAP_DEBUG_TRACE, "%s <<< asyncmeta_back_modify_start[%p]=%d\n", op->o_log_prefix, msc, candidates[candidate].sr_msgid );
        return retcode;
index 0a78e765a7558aafbb1291f3fe87ad6be029057b..459e835a588633d7a8e8f04e964cea1c328d4bad 100644 (file)
@@ -74,18 +74,8 @@ meta_back_modify( Operation *op, SlapReply *rs )
        for ( i = 0, ml = op->orm_modlist; ml; i++ ,ml = ml->sml_next )
                ;
 
-       mods = ch_malloc( sizeof( LDAPMod )*i );
-       if ( mods == NULL ) {
-               rs->sr_err = LDAP_OTHER;
-               send_ldap_result( op, rs );
-               goto cleanup;
-       }
-       modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
-       if ( modv == NULL ) {
-               rs->sr_err = LDAP_OTHER;
-               send_ldap_result( op, rs );
-               goto cleanup;
-       }
+       modv = ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) + i*sizeof( LDAPMod ) );
+       mods = (LDAPMod *)&modv[ i + 1 ];
 
        dc.ctx = "modifyAttrDN";
        isupdate = be_shadow_update( op );
@@ -206,11 +196,10 @@ cleanup:;
        }
        if ( modv != NULL ) {
                for ( i = 0; modv[ i ]; i++ ) {
-                       free( modv[ i ]->mod_bvalues );
+                       ch_free( modv[ i ]->mod_bvalues );
                }
        }
-       free( mods );
-       free( modv );
+       ch_free( modv );
 
        if ( mc ) {
                meta_back_release_conn( mi, mc );