From: Kurt Zeilenga Date: Mon, 2 Oct 2000 17:43:06 +0000 (+0000) Subject: Rework stringal decode to return { NULL, 0 } bv's instead of { "", 0 } X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1836 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=822bfc3670e04b66c3ecbd1f917a5dd8d7a16ce2;p=openldap Rework stringal decode to return { NULL, 0 } bv's instead of { "", 0 } when len is 0. --- diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index ef12bf46d6..e55354f5e1 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -297,23 +297,33 @@ ber_get_stringal( BerElement *ber, struct berval **bv ) if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) { *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } - if ( (*bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) )) == NULL ) - return( LBER_DEFAULT ); + *bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) ); + if ( *bv == NULL ) { + return LBER_DEFAULT; + } - if ( ((*bv)->bv_val = (char *) LBER_MALLOC( len + 1 )) == NULL ) { + if( len == 0 ) { + (*bv)->bv_val = NULL; + (*bv)->bv_len = 0; + return tag; + } + + (*bv)->bv_val = (char *) LBER_MALLOC( len + 1 ); + if ( (*bv)->bv_val == NULL ) { LBER_FREE( *bv ); *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } if ( (ber_len_t) ber_read( ber, (*bv)->bv_val, len ) != len ) { ber_bvfree( *bv ); *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } + ((*bv)->bv_val)[len] = '\0'; (*bv)->bv_len = len;