]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/accesslog.c
check for NULL backend (ITS#6490)
[openldap] / servers / slapd / overlays / accesslog.c
index 90ec25857a0ed91b8dc292a0d321302216feac5b..d9a576b775338d64116524bae79f6d8a82714767 100644 (file)
@@ -580,11 +580,12 @@ log_old_lookup( Operation *op, SlapReply *rs )
        a = attr_find( rs->sr_entry->e_attrs,
                slap_schema.si_ad_entryCSN );
        if ( a ) {
-               ber_len_t len = a->a_vals[0].bv_len;
-               if ( len > pd->csn.bv_len )
-                       len = pd->csn.bv_len;
-               if ( memcmp( a->a_vals[0].bv_val, pd->csn.bv_val, len ) > 0 ) {
-                       AC_MEMCPY( pd->csn.bv_val, a->a_vals[0].bv_val, len );
+               ber_len_t len = a->a_nvals[0].bv_len;
+               /* Paranoid len check, normalized CSNs are always the same length */
+               if ( len > LDAP_PVT_CSNSTR_BUFSIZE )
+                       len = LDAP_PVT_CSNSTR_BUFSIZE;
+               if ( memcmp( a->a_nvals[0].bv_val, pd->csn.bv_val, len ) > 0 ) {
+                       AC_MEMCPY( pd->csn.bv_val, a->a_nvals[0].bv_val, len );
                        pd->csn.bv_len = len;
                }
        }
@@ -615,7 +616,7 @@ accesslog_purge( void *ctx, void *arg )
        AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
        purge_data pd = {0};
        char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
-       char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
+       char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
        time_t old = slap_get_time();
 
        connection_fake_init( &conn, &opbuf, ctx );
@@ -1260,7 +1261,7 @@ static Entry *accesslog_entry( Operation *op, SlapReply *rs, int logop,
        }
 
        rdn.bv_len = snprintf( rdn.bv_val, sizeof( rdnbuf ), "%lu", op->o_connid );
-       if ( rdn.bv_len >= 0 || rdn.bv_len < sizeof( rdnbuf ) ) {
+       if ( rdn.bv_len < sizeof( rdnbuf ) ) {
                attr_merge_one( e, ad_reqSession, &rdn, NULL );
        } /* else? */
 
@@ -1551,22 +1552,24 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                                        i += a->a_numvals;
                                }
                        }
-                       vals = ch_malloc( (i + 1) * sizeof( struct berval ) );
-                       i = 0;
-                       for ( a=old->e_attrs; a; a=a->a_next ) {
-                               if ( a->a_vals && a->a_flags ) {
-                                       for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
-                                               accesslog_val2val( a->a_desc, b, 0, &vals[i] );
+                       if ( i ) {
+                               vals = ch_malloc( (i + 1) * sizeof( struct berval ) );
+                               i = 0;
+                               for ( a=old->e_attrs; a; a=a->a_next ) {
+                                       if ( a->a_vals && a->a_flags ) {
+                                               for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
+                                                       accesslog_val2val( a->a_desc, b, 0, &vals[i] );
+                                               }
                                        }
                                }
+                               vals[i].bv_val = NULL;
+                               vals[i].bv_len = 0;
+                               a = attr_alloc( ad_reqOld );
+                               a->a_numvals = i;
+                               a->a_vals = vals;
+                               a->a_nvals = vals;
+                               last_attr->a_next = a;
                        }
-                       vals[i].bv_val = NULL;
-                       vals[i].bv_len = 0;
-                       a = attr_alloc( ad_reqOld );
-                       a->a_numvals = i;
-                       a->a_vals = vals;
-                       a->a_nvals = vals;
-                       last_attr->a_next = a;
                }
                if ( logop == LOG_EN_MODIFY ) {
                        break;
@@ -1770,7 +1773,7 @@ accesslog_op_mod( Operation *op, SlapReply *rs )
                        int rc;
                        Entry *e;
 
-                       op->o_bd->bd_info = on->on_info->oi_orig;
+                       op->o_bd->bd_info = (BackendInfo *)on->on_info;
                        rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
                        if ( e ) {
                                if ( test_filter( op, e, li->li_oldf ) == LDAP_COMPARE_TRUE )