From 450e0d6803191ffe1b0dcb6dfcffd010203ddbf2 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 24 Dec 2001 07:22:25 +0000 Subject: [PATCH] Some minor bugs for dntest "" --- libraries/libldap/dntest.c | 47 ++++++++++++++++++++++++-------------- libraries/libldap/getdn.c | 18 +++++++++++---- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/libraries/libldap/dntest.c b/libraries/libldap/dntest.c index a1a65f5feb..ffbc28b4cc 100644 --- a/libraries/libldap/dntest.c +++ b/libraries/libldap/dntest.c @@ -120,22 +120,27 @@ main( int argc, char *argv[] ) if ( rc == LDAP_SUCCESS ) { int i; - for ( i = 0; dn[ i ]; i++ ) { - LDAPRDN *rdn = dn[ i ][ 0 ]; - char *rstr; + if( dn ) { + for ( i = 0; dn[i]; i++ ) { + LDAPRDN *rdn = dn[ i ][ 0 ]; + char *rstr; - if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) { - fprintf( stdout, "\tldap_rdn2str() failed\n" ); - continue; + if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) { + fprintf( stdout, "\tldap_rdn2str() failed\n" ); + continue; + } + + fprintf( stdout, "\tldap_rdn2str() = \"%s\"\n", rstr ); + ldap_memfree( rstr ); } - - fprintf( stdout, "\tldap_rdn2str() = \"%s\"\n", rstr ); - ldap_memfree( rstr ); + } else { + fprintf( stdout, "\tempty DN\n" ); } } - if ( rc == LDAP_SUCCESS && - ldap_dn2str( dn, &str, flags[ f2 ] ) == LDAP_SUCCESS ) { + if ( rc == LDAP_SUCCESS && + ldap_dn2str( dn, &str, flags[ f2 ] ) == LDAP_SUCCESS ) + { char **values, *tmp, *tmp2; int n; @@ -216,7 +221,13 @@ main( int argc, char *argv[] ) str, str2, strcmp( str, str2 ) == 0 ? "yes" : "no" ); - for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ ) { + if(( dn != NULL && dn2 == NULL ) + || ( dn != NULL && dn2 == NULL )) + { + fprintf( stdout, "mismatch\n" ); + } else if (( dn != NULL ) && (dn2 != NULL)) + for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ ) + { LDAPRDN *r = dn[ iRDN ][ 0 ]; LDAPRDN *r2 = dn2[ iRDN ][ 0 ]; int iAVA; @@ -226,12 +237,14 @@ main( int argc, char *argv[] ) LDAPAVA *a2 = r2[ iAVA ][ 0 ]; if ( a->la_attr->bv_len != a2->la_attr->bv_len - || memcmp( a->la_attr->bv_val, a2->la_attr->bv_val, a->la_attr->bv_len ) - || a->la_flags != a2->la_flags - || a->la_value->bv_len != a2->la_value->bv_len - || memcmp( a->la_value->bv_val, a2->la_value->bv_val, a->la_value->bv_len ) ) { + || memcmp( a->la_attr->bv_val, a2->la_attr->bv_val, + a->la_attr->bv_len ) + || a->la_flags != a2->la_flags + || a->la_value->bv_len != a2->la_value->bv_len + || memcmp( a->la_value->bv_val, a2->la_value->bv_val, + a->la_value->bv_len ) ) + { fprintf( stdout, "mismatch\n" ); - } } } diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 4d4b29133c..21980226d1 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -141,7 +141,15 @@ ldap_explode_dn( LDAP_CONST char *dn, int notypes ) if ( ldap_str2dn( dn, &tmpDN, LDAP_DN_FORMAT_LDAP ) != LDAP_SUCCESS ) { - return( NULL ); + return NULL; + } + + if( tmpDN == NULL ) { + values = LDAP_MALLOC( sizeof( char * ) ); + if( values == NULL ) return NULL; + + values[0] = NULL; + return values; } for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) { @@ -149,18 +157,18 @@ ldap_explode_dn( LDAP_CONST char *dn, int notypes ) ldap_rdn2str( tmpDN[ iRDN ][ 0 ], &str, flag ); - v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iRDN ) ); + v = LDAP_REALLOC( values, sizeof( char * ) * ( iRDN + 1 ) ); if ( v == NULL ) { LBER_VFREE( values ); ldap_dnfree( tmpDN ); - return( NULL ); + return NULL; } values = v; values[ iRDN ] = str; } - values[ iRDN ] = NULL; - return( values ); + values[ iRDN ] = NULL; + return values; } char **