]> git.sur5r.net Git - openldap/commitdiff
Fix uninit'd var, check for single-valued attrs
authorHoward Chu <hyc@openldap.org>
Wed, 24 Aug 2005 01:34:49 +0000 (01:34 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 24 Aug 2005 01:34:49 +0000 (01:34 +0000)
servers/slapd/overlays/valsort.c

index 3d064e03e63a9d2127062bcdb2e3772ce2521b40..c5a14ffad5051d4820822be4d666bd18c71ea35c 100644 (file)
@@ -87,7 +87,7 @@ valsort_cf_func(ConfigArgs *c) {
        valsort_info vitmp, *vi;
        const char *text = NULL;
        int i;
-       struct berval bv;
+       struct berval bv = BER_BVNULL;
 
        if ( c->op == SLAP_CONFIG_EMIT ) {
                for ( vi = on->on_bi.bi_private; vi; vi = vi->vi_next ) {
@@ -112,12 +112,14 @@ valsort_cf_func(ConfigArgs *c) {
                        *ptr++ = '"';
                        ptr = lutil_strcopy( ptr, vi->vi_dn.bv_val );
                        *ptr++ = '"';
-                       *ptr++ = ' ';
                        if ( vi->vi_sort & VALSORT_WEIGHTED ) {
+                               *ptr++ = ' ';
                                ptr = lutil_strcopy( ptr, bv2.bv_val );
+                       }
+                       if ( !BER_BVISNULL( &bv )) {
                                *ptr++ = ' ';
+                               strcpy( ptr, bv.bv_val );
                        }
-                       strcpy( ptr, bv.bv_val );
                        ber_bvarray_add( &c->rvalue_vals, &bvret );
                }
                i = ( c->rvalue_vals != NULL ) ? 0 : 1;
@@ -149,6 +151,13 @@ valsort_cf_func(ConfigArgs *c) {
                        c->log, c->msg, c->argv[1] );
                return(1);
        }
+       if ( is_at_single_value( vitmp.vi_ad->ad_type )) {
+               sprintf( c->msg, "<%s> %s is single-valued, ignoring", c->argv[0],
+                       vitmp.vi_ad->ad_cname.bv_val );
+               Debug( LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
+                       c->log, c->msg, c->argv[1] );
+               return(0);
+       }
        ber_str2bv( c->argv[2], 0, 0, &bv );
        i = dnNormalize( 0, NULL, NULL, &bv, &vitmp.vi_dn, NULL );
        if ( i ) {