[Date Prev][Date Next] [Chronological] [Thread] [Top]

slapd bug for SYNTAX_BIN EQUALITY comparisons



The result set of an EQUALITY search on a SYNTAX_BIN attribute may be
incorrect because value_cmp() in value.c compares two attributes by
comparing the leading bytes of the two values (candidate and filter) up to
the smaller of the two lengths of the binary values. If the lengths of two
SYNTAX_BIN values differ, like SYNTAX_CES and SYNTAX_CIS, the EQUALITY
comparison should fail.

It also appears that value_ncmp() in value.c has no references anywhere in
the openLDAP source tree, save for a definition in proto-slap.h. The
following fix the bug and remove the dead code:

*** value.c.orig	Sat Oct 24 18:42:01 1998
--- value.c	Fri Dec 11 17:46:57 1998
***************
*** 103,110 ****
  	*d = '\0';
  }
  
- #define LDAP_MIN( a, b )	((a) < (b) ? (a) : (b) )
- 
  int
  value_cmp(
      struct berval	*v1,
--- 103,108 ----
***************
*** 137,189 ****
  		break;
  
  	case SYNTAX_BIN:
! 		rc = memcmp( v1->bv_val, v2->bv_val, LDAP_MIN( v1->bv_len,
! 		    v2->bv_len ) );
  		break;
- 	}
- 
- 	if ( normalize & 1 ) {
- 		ber_bvfree( v1 );
- 	}
- 	if ( normalize & 2 ) {
- 		ber_bvfree( v2 );
- 	}
- 
- 	return( rc );
- }
- 
- int
- value_ncmp(
-     struct berval	*v1,
-     struct berval	*v2,
-     int			syntax,
-     int			len,
-     int			normalize
- )
- {
- 	int	rc;
- 
- 	if ( normalize & 1 ) {
- 		v1 = ber_bvdup( v1 );
- 		value_normalize( v1->bv_val, syntax );
- 	}
- 	if ( normalize & 2 ) {
- 		v2 = ber_bvdup( v2 );
- 		value_normalize( v2->bv_val, syntax );
- 	}
- 
- 	switch ( syntax ) {
- 	case SYNTAX_CIS:
- 	case (SYNTAX_CIS | SYNTAX_TEL):
- 		rc = strncasecmp( v1->bv_val, v2->bv_val, len );
- 		break;
- 
- 	case SYNTAX_CES:
- 		rc = strncmp( v1->bv_val, v2->bv_val, len );
- 		break;
- 
- 	case SYNTAX_BIN:
- 		rc = memcmp( v1->bv_val, v2->bv_val, len );
  	}
  
  	if ( normalize & 1 ) {
--- 135,143 ----
  		break;
  
  	case SYNTAX_BIN:
! 		rc = ( v1->bv_len == v2->bv_len ) ? memcmp( v1->bv_val, 
! 		    v2->bv_val, v1->bv_len ) : v1->bv_len - v2->bv_len ;
  		break;
  	}
  
  	if ( normalize & 1 ) {
  
*** proto-slap.h.orig	Fri Nov 27 13:21:55 1998
--- proto-slap.h	Fri Dec 11 17:41:52 1998
***************
*** 208,215 ****
  void value_normalize LDAP_P(( char *s, int syntax ));
  int value_cmp LDAP_P(( struct berval *v1, struct berval *v2, int syntax,
  	int normalize ));
- int value_ncmp LDAP_P(( struct berval *v1, struct berval *v2, int syntax,
int len,
- 	int normalize ));
  int value_find LDAP_P(( struct berval **vals, struct berval *v, int
syntax,
  	int normalize ));
  
--- 208,213 ----


Ken McGarrahan
Southwestern Bell Telephone
*	Phone: (314) 235-3160
*	E-Mail: km4155@sbc.com