From: Howard Chu Date: Sat, 1 Dec 2007 11:41:52 +0000 (+0000) Subject: Omit leading zero pad byte X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~371 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=95993844ddf547c50878a789367b3d8f574f812c;p=openldap Omit leading zero pad byte --- diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index cb18fbae5c..9ac07b326e 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -2119,30 +2119,38 @@ integerVal2Key( struct berval *tmp ) { + struct berval iv; int neg; - if ( lutil_str2bin( val, tmp )) { + iv = *tmp; + if ( lutil_str2bin( val, &iv )) { return LDAP_INVALID_SYNTAX; } - neg = tmp->bv_val[0] & 0x80; + neg = iv.bv_val[0] & 0x80; + + /* Omit leading 0 pad byte */ + if ( !iv.bv_val[0] ) { + iv.bv_val++; + iv.bv_len--; + } /* If too small, sign-extend */ - if ( tmp->bv_len < index_intlen ) { + if ( iv.bv_len < index_intlen ) { int j, k, pad; key->bv_val[0] = index_intlen; - k = index_intlen - tmp->bv_len + 1; + k = index_intlen - iv.bv_len + 1; if ( neg ) pad = 0xff; else pad = 0; for ( j=1; jbv_val[j] = pad; - for ( j = 0; jbv_len; j++ ) - key->bv_val[j+k] = tmp->bv_val[j]; + for ( j = 0; jbv_val[j+k] = iv.bv_val[j]; } else { - key->bv_val[0] = tmp->bv_len; - memcpy( key->bv_val+1, tmp->bv_val, index_intlen ); + key->bv_val[0] = iv.bv_len; + memcpy( key->bv_val+1, iv.bv_val, index_intlen ); } if ( neg ) { key->bv_val[0] = -key->bv_val[0];