]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / slapi / slapi_utils.c
index 5a389fb0534f207a0f80019cb02eb6a28b437afe..702042fbc773f9a1b16401af162c3149e1e6247d 100644 (file)
@@ -902,6 +902,7 @@ slapi_dn_issuffix(
 #ifdef LDAP_SLAPI
        struct berval   bdn, ndn;
        struct berval   bsuffix, nsuffix;
+       int rc;
 
        assert( dn != NULL );
        assert( suffix != NULL );
@@ -912,10 +913,21 @@ slapi_dn_issuffix(
        bsuffix.bv_val = suffix;
        bsuffix.bv_len = strlen( suffix );
 
-       dnNormalize2( NULL, &bdn, &ndn );
-       dnNormalize2( NULL, &bsuffix, &nsuffix );
+       if ( dnNormalize2( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) {
+               return 0;
+       }
+
+       if ( dnNormalize2( NULL, &bsuffix, &nsuffix ) != LDAP_SUCCESS ) {
+               slapi_ch_free( (void **)&ndn.bv_val );
+               return 0;
+       }
 
-       return dnIsSuffix( &ndn, &nsuffix );
+       rc = dnIsSuffix( &ndn, &nsuffix );
+
+       slapi_ch_free( (void **)&ndn.bv_val );
+       slapi_ch_free( (void **)&nsuffix.bv_val );
+
+       return rc;
 #else /* LDAP_SLAPI */
        return 0;
 #endif /* LDAP_SLAPI */
@@ -1363,25 +1375,24 @@ slapi_send_ldap_result(
        rs.sr_ref = NULL;
        rs.sr_ctrls = NULL;
 
+       slapi_pblock_get( pb, SLAPI_RESCONTROLS, &rs.sr_ctrls );
+
        if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
-               rs.sr_type = REP_SASL;
                slapi_pblock_get( pb, SLAPI_BIND_RET_SASLCREDS, (void *) &rs.sr_sasldata );
-
                send_ldap_sasl( op, &rs );
                return;
        }
 
        slapi_pblock_get( pb, SLAPI_EXT_OP_RET_OID, &extOID );
        if ( extOID != NULL ) {
-               rs.sr_type = REP_EXTENDED;
                rs.sr_rspoid = extOID;
                slapi_pblock_get( pb, SLAPI_EXT_OP_RET_VALUE, &rs.sr_rspdata );
                send_ldap_extended( op, &rs );
                return;
        }
 
-       rs.sr_type = REP_RESULT;
-       slapi_pblock_get( pb, SLAPI_RESCONTROLS, &rs.sr_ctrls );
+       if (op->o_tag == LDAP_REQ_SEARCH)
+               rs.sr_nentries = nentries;
 
        send_ldap_result( op, &rs );
 #endif /* LDAP_SLAPI */
@@ -1419,7 +1430,6 @@ slapi_send_ldap_search_entry(
                an[i].an_name.bv_val = NULL;
        }
 
-       rs.sr_type = REP_SEARCH;
        rs.sr_err = LDAP_SUCCESS;
        rs.sr_matched = NULL;
        rs.sr_text = NULL;
@@ -1855,7 +1865,6 @@ slapi_send_ldap_extended_response(
 #ifdef LDAP_SLAPI
        SlapReply       rs;
 
-       rs.sr_type = REP_EXTENDED;
        rs.sr_err = errornum;
        rs.sr_matched = NULL;
        rs.sr_text = NULL;
@@ -3195,7 +3204,7 @@ LDAPMod **slapi_x_modifications2ldapmods(Modifications **pmodlist)
 Modifications *slapi_x_ldapmods2modifications (LDAPMod **mods)
 {
 #ifdef LDAP_SLAPI
-       Modifications *modlist, **modtail;
+       Modifications *modlist = NULL, **modtail;
        LDAPMod **modp;
 
        modtail = &modlist;