Never let ldif_parse_line() return a NULL value with success.

This commit is contained in:
Hallvard Furuseth 2002-12-02 22:46:07 +00:00
parent 3121074ad7
commit 416aeb9347
4 changed files with 17 additions and 26 deletions

View File

@ -976,12 +976,12 @@ process_ldif_rec( char *rbuf, int count )
{ {
if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) { if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
fprintf( stderr, "%s: invalid version %s, line %d (ignored)\n", 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++; version++;
} else if ( strcasecmp( type, T_DN_STR ) == 0 ) { } 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" ); perror( "strdup" );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -1097,7 +1097,7 @@ process_ldif_rec( char *rbuf, int count )
if ( expect_newrdn ) { if ( expect_newrdn ) {
if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) { 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" ); perror( "strdup" );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -1121,7 +1121,7 @@ process_ldif_rec( char *rbuf, int count )
} }
} else if ( expect_newsup ) { } else if ( expect_newsup ) {
if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) { 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" ); perror( "strdup" );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -1137,7 +1137,7 @@ process_ldif_rec( char *rbuf, int count )
prog, linenum, dn ); prog, linenum, dn );
rc = LDAP_PARAM_ERROR; rc = LDAP_PARAM_ERROR;
} else { } else {
addmodifyop( &pmods, modop, type, val.bv_val == NULL ? NULL : &val ); addmodifyop( &pmods, modop, type, &val );
} }
end_line: end_line:

View File

@ -143,9 +143,8 @@ ldif_parse_line(
/* no value is present, error out */ /* no value is present, error out */
ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug, ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
"ldif_parse_line: %s missing base64 value\n", type ); "ldif_parse_line: %s missing base64 value\n", type );
value = NULL; ber_memfree( freeme );
vlen = 0; return( -1 );
goto done;
} }
byte = value = s; byte = value = s;
@ -196,9 +195,8 @@ ldif_parse_line(
/* no value is present, error out */ /* no value is present, error out */
ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug, ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
"ldif_parse_line: %s missing URL value\n", type ); "ldif_parse_line: %s missing URL value\n", type );
value = NULL; ber_memfree( freeme );
vlen = 0; return( -1 );
goto done;
} }
if( ldif_fetch_url( s, &value, &vlen ) ) { if( ldif_fetch_url( s, &value, &vlen ) ) {
@ -214,7 +212,6 @@ ldif_parse_line(
vlen = (int) (d - s); vlen = (int) (d - s);
} }
done:
type = ber_strdup( type ); type = ber_strdup( type );
if( type == NULL ) { if( type == NULL ) {
@ -225,7 +222,7 @@ done:
return( -1 ); return( -1 );
} }
if( !url && value != NULL ) { if( !url ) {
p = ber_memalloc( vlen + 1 ); p = ber_memalloc( vlen + 1 );
if( p == NULL ) { if( p == NULL ) {
ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug, ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,

View File

@ -112,15 +112,13 @@ str2entry( char *s )
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG( OPERATION, DETAIL1, "str2entry: " LDAP_LOG( OPERATION, DETAIL1, "str2entry: "
"entry %ld has multiple DNs \"%s\" and \"%s\"\n", "entry %ld has multiple DNs \"%s\" and \"%s\"\n",
(long) e->e_id, e->e_dn, (long) e->e_id, e->e_dn, vals[0].bv_val );
vals[0].bv_val != NULL ? vals[0].bv_val : "" );
#else #else
Debug( LDAP_DEBUG_ANY, "str2entry: " Debug( LDAP_DEBUG_ANY, "str2entry: "
"entry %ld has multiple DNs \"%s\" and \"%s\"\n", "entry %ld has multiple DNs \"%s\" and \"%s\"\n",
(long) e->e_id, e->e_dn, (long) e->e_id, e->e_dn, vals[0].bv_val );
vals[0].bv_val != NULL ? vals[0].bv_val : "" );
#endif #endif
if( vals[0].bv_val != NULL ) free( vals[0].bv_val ); free( vals[0].bv_val );
entry_free( e ); entry_free( e );
return NULL; return NULL;
} }

View File

@ -221,13 +221,11 @@ Re_parse(
type, 0, 0 ); type, 0, 0 );
#endif #endif
free( type ); free( type );
if ( value != NULL )
free( value ); free( value );
return -1; return -1;
} }
} }
free( type ); free( type );
if ( value != NULL )
free( value ); free( value );
} }
@ -367,7 +365,6 @@ get_repl_hosts(
free( type ); free( type );
if ( !repl_ok ) { if ( !repl_ok ) {
warn_unknown_replica( value, port ); warn_unknown_replica( value, port );
if ( value != NULL )
free( value ); free( value );
continue; continue;
} }
@ -387,7 +384,6 @@ get_repl_hosts(
rh[ nreplicas ].rh_port = port; rh[ nreplicas ].rh_port = port;
nreplicas++; nreplicas++;
if ( value != NULL )
free( value ); free( value );
} }