From 416aeb9347609866126a71de112afdefdff829bf Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Mon, 2 Dec 2002 22:46:07 +0000 Subject: [PATCH] Never let ldif_parse_line() return a NULL value with success. --- clients/tools/ldapmodify.c | 10 +++++----- libraries/libldif/line64.c | 13 +++++-------- servers/slapd/entry.c | 8 +++----- servers/slurpd/re.c | 12 ++++-------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index a131d4cab2..00c1899905 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -976,12 +976,12 @@ process_ldif_rec( char *rbuf, int count ) { if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) { fprintf( stderr, "%s: invalid version %s, line %d (ignored)\n", - prog, val.bv_val == NULL ? "(null)" : val.bv_val, linenum ); + prog, val.bv_val, linenum ); } version++; } else if ( strcasecmp( type, T_DN_STR ) == 0 ) { - if (( dn = ber_strdup( val.bv_val ? val.bv_val : "" )) == NULL ) { + if (( dn = ber_strdup( val.bv_val )) == NULL ) { perror( "strdup" ); exit( EXIT_FAILURE ); } @@ -1097,7 +1097,7 @@ process_ldif_rec( char *rbuf, int count ) if ( expect_newrdn ) { if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) { - if (( newrdn = ber_strdup( val.bv_val ? val.bv_val : "" )) == NULL ) { + if (( newrdn = ber_strdup( val.bv_val )) == NULL ) { perror( "strdup" ); exit( EXIT_FAILURE ); } @@ -1121,7 +1121,7 @@ process_ldif_rec( char *rbuf, int count ) } } else if ( expect_newsup ) { if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) { - if (( newsup = ber_strdup( val.bv_val ? val.bv_val : "" )) == NULL ) { + if (( newsup = ber_strdup( val.bv_val )) == NULL ) { perror( "strdup" ); exit( EXIT_FAILURE ); } @@ -1137,7 +1137,7 @@ process_ldif_rec( char *rbuf, int count ) prog, linenum, dn ); rc = LDAP_PARAM_ERROR; } else { - addmodifyop( &pmods, modop, type, val.bv_val == NULL ? NULL : &val ); + addmodifyop( &pmods, modop, type, &val ); } end_line: diff --git a/libraries/libldif/line64.c b/libraries/libldif/line64.c index 94c3f9dd4b..1d0310793b 100644 --- a/libraries/libldif/line64.c +++ b/libraries/libldif/line64.c @@ -143,9 +143,8 @@ ldif_parse_line( /* no value is present, error out */ ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug, "ldif_parse_line: %s missing base64 value\n", type ); - value = NULL; - vlen = 0; - goto done; + ber_memfree( freeme ); + return( -1 ); } byte = value = s; @@ -196,9 +195,8 @@ ldif_parse_line( /* no value is present, error out */ ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug, "ldif_parse_line: %s missing URL value\n", type ); - value = NULL; - vlen = 0; - goto done; + ber_memfree( freeme ); + return( -1 ); } if( ldif_fetch_url( s, &value, &vlen ) ) { @@ -214,7 +212,6 @@ ldif_parse_line( vlen = (int) (d - s); } -done: type = ber_strdup( type ); if( type == NULL ) { @@ -225,7 +222,7 @@ done: return( -1 ); } - if( !url && value != NULL ) { + if( !url ) { p = ber_memalloc( vlen + 1 ); if( p == NULL ) { ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug, diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 98f5842f8a..b07ad02b43 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -112,15 +112,13 @@ str2entry( char *s ) #ifdef NEW_LOGGING LDAP_LOG( OPERATION, DETAIL1, "str2entry: " "entry %ld has multiple DNs \"%s\" and \"%s\"\n", - (long) e->e_id, e->e_dn, - vals[0].bv_val != NULL ? vals[0].bv_val : "" ); + (long) e->e_id, e->e_dn, vals[0].bv_val ); #else Debug( LDAP_DEBUG_ANY, "str2entry: " "entry %ld has multiple DNs \"%s\" and \"%s\"\n", - (long) e->e_id, e->e_dn, - vals[0].bv_val != NULL ? vals[0].bv_val : "" ); + (long) e->e_id, e->e_dn, vals[0].bv_val ); #endif - if( vals[0].bv_val != NULL ) free( vals[0].bv_val ); + free( vals[0].bv_val ); entry_free( e ); return NULL; } diff --git a/servers/slurpd/re.c b/servers/slurpd/re.c index dbde0bc43d..e0b38c65e3 100644 --- a/servers/slurpd/re.c +++ b/servers/slurpd/re.c @@ -221,14 +221,12 @@ Re_parse( type, 0, 0 ); #endif free( type ); - if ( value != NULL ) - free( value ); + free( value ); return -1; } } free( type ); - if ( value != NULL ) - free( value ); + free( value ); } if ( state != GOT_ALL ) { @@ -367,8 +365,7 @@ get_repl_hosts( free( type ); if ( !repl_ok ) { warn_unknown_replica( value, port ); - if ( value != NULL ) - free( value ); + free( value ); continue; } @@ -387,8 +384,7 @@ get_repl_hosts( rh[ nreplicas ].rh_port = port; nreplicas++; - if ( value != NULL ) - free( value ); + free( value ); } if ( nreplicas == 0 ) { -- 2.39.5