]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/accesslog.c
check for NULL backend (ITS#6490)
[openldap] / servers / slapd / overlays / accesslog.c
index 722bd0cfa26c90edc707137c9161c8d75ba2cf6a..d9a576b775338d64116524bae79f6d8a82714767 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2005-2008 The OpenLDAP Foundation.
+ * Copyright 2005-2009 The OpenLDAP Foundation.
  * Portions copyright 2004-2005 Symas Corporation.
  * All rights reserved.
  *
@@ -534,17 +534,17 @@ log_age_unparse( int age, struct berval *agebv, size_t size )
 
        if ( dd ) {
                len = snprintf( ptr, size, "%d+", dd );
-               assert( len >= 0 && len < size );
+               assert( len >= 0 && (unsigned) len < size );
                size -= len;
                ptr += len;
        }
        len = snprintf( ptr, size, "%02d:%02d", hh, mm );
-       assert( len >= 0 && len < size );
+       assert( len >= 0 && (unsigned) len < size );
        size -= len;
        ptr += len;
        if ( ss ) {
                len = snprintf( ptr, size, ":%02d", ss );
-               assert( len >= 0 && len < size );
+               assert( len >= 0 && (unsigned) len < size );
                size -= len;
                ptr += len;
        }
@@ -579,10 +579,15 @@ log_old_lookup( Operation *op, SlapReply *rs )
         */
        a = attr_find( rs->sr_entry->e_attrs,
                slap_schema.si_ad_entryCSN );
-       if ( a && ber_bvcmp( &a->a_vals[0], &pd->csn ) > 0 ) {
-               AC_MEMCPY( pd->csn.bv_val, a->a_vals[0].bv_val,
-                       a->a_vals[0].bv_len );
-               pd->csn.bv_len = a->a_vals[0].bv_len;
+       if ( a ) {
+               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;
+               }
        }
        if ( pd->used >= pd->slots ) {
                pd->slots += PURGE_INCREMENT;
@@ -611,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 );
@@ -929,7 +934,7 @@ logSchemaControlValidate(
        struct berval   *valp )
 {
        struct berval   val, bv;
-       int             i;
+       ber_len_t               i;
        int             rc = LDAP_SUCCESS;
 
        assert( valp != NULL );
@@ -1151,7 +1156,7 @@ accesslog_ctrls(
                }
                
                if ( !BER_BVISNULL( &ctrls[ i ]->ldctl_value ) ) {
-                       int     j;
+                       ber_len_t       j;
 
                        ptr = lutil_strcopy( ptr, " controlValue \"" );
                        for ( j = 0; j < ctrls[ i ]->ldctl_value.bv_len; j++ )
@@ -1256,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? */
 
@@ -1396,7 +1401,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                attr_merge_one( e, ad_reqMessage, &bv, NULL );
        }
        bv.bv_len = snprintf( timebuf, sizeof( timebuf ), "%d", rs->sr_err );
-       if ( bv.bv_len >= 0 && bv.bv_len < sizeof( timebuf ) ) {
+       if ( bv.bv_len < sizeof( timebuf ) ) {
                bv.bv_val = timebuf;
                attr_merge_one( e, ad_reqResult, &bv, NULL );
        }
@@ -1547,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;
@@ -1613,17 +1620,17 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                }
                bv.bv_val = timebuf;
                bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", rs->sr_nentries );
-               if ( bv.bv_len >= 0 && bv.bv_len < sizeof( timebuf ) ) {
+               if ( bv.bv_len < sizeof( timebuf ) ) {
                        attr_merge_one( e, ad_reqEntries, &bv, NULL );
                } /* else? */
 
                bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->ors_tlimit );
-               if ( bv.bv_len >= 0 && bv.bv_len < sizeof( timebuf ) ) {
+               if ( bv.bv_len < sizeof( timebuf ) ) {
                        attr_merge_one( e, ad_reqTimeLimit, &bv, NULL );
                } /* else? */
 
                bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->ors_slimit );
-               if ( bv.bv_len >= 0 && bv.bv_len < sizeof( timebuf ) ) {
+               if ( bv.bv_len < sizeof( timebuf ) ) {
                        attr_merge_one( e, ad_reqSizeLimit, &bv, NULL );
                } /* else? */
                break;
@@ -1631,7 +1638,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        case LOG_EN_BIND:
                bv.bv_val = timebuf;
                bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->o_protocol );
-               if ( bv.bv_len >= 0 && bv.bv_len < sizeof( timebuf ) ) {
+               if ( bv.bv_len < sizeof( timebuf ) ) {
                        attr_merge_one( e, ad_reqVersion, &bv, NULL );
                } /* else? */
                if ( op->orb_method == LDAP_AUTH_SIMPLE ) {
@@ -1766,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 )
@@ -1834,7 +1841,7 @@ accesslog_abandon( Operation *op, SlapReply *rs )
        e = accesslog_entry( op, rs, LOG_EN_ABANDON, &op2 );
        bv.bv_val = buf;
        bv.bv_len = snprintf( buf, sizeof( buf ), "%d", op->orn_msgid );
-       if ( bv.bv_len >= 0 && bv.bv_len < sizeof( buf ) ) {
+       if ( bv.bv_len < sizeof( buf ) ) {
                attr_merge_one( e, ad_reqId, &bv, NULL );
        } /* else? */