From b92e0011dd77145d1724fc7597ce9a5701f1e811 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 6 Jan 2002 02:23:36 +0000 Subject: [PATCH] Prep for in-place parsing. Cache a ber_tag byte. No visible impact from these changes. --- libraries/liblber/decode.c | 20 ++++++++++++++++++-- libraries/liblber/io.c | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index 1d4899f985..807bb98de4 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -44,10 +44,16 @@ ber_get_tag( BerElement *ber ) assert( ber != NULL ); assert( LBER_VALID( ber ) ); - if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) { + if ( ber_pvt_ber_remaining( ber ) < 1 ) { return LBER_DEFAULT; } + if ( ber->ber_ptr == ber->ber_buf ) + xbyte = *ber->ber_ptr; + else + xbyte = ber->ber_tag; + ber->ber_ptr++; + tag = xbyte; if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) { @@ -146,6 +152,7 @@ ber_skip_tag( BerElement *ber, ber_len_t *len ) if( *len > (ber_len_t) ber_pvt_ber_remaining( ber ) ) { return LBER_DEFAULT; } + ber->ber_tag = *ber->ber_ptr; return tag; } @@ -161,11 +168,13 @@ ber_peek_tag( */ char *save; - ber_tag_t tag; + ber_tag_t tag, old; + old = ber->ber_tag; save = ber->ber_ptr; tag = ber_skip_tag( ber, len ); ber->ber_ptr = save; + ber->ber_tag = old; return tag; } @@ -213,6 +222,7 @@ ber_getnint( } else { *num = 0; } + ber->ber_tag = *ber->ber_ptr; return len; } @@ -271,6 +281,7 @@ ber_get_stringb( if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen ) { return LBER_DEFAULT; } + ber->ber_tag = *ber->ber_ptr; buf[datalen] = '\0'; @@ -423,6 +434,7 @@ ber_get_stringbv( BerElement *ber, struct berval *bv ) return LBER_DEFAULT; } bv->bv_val[bv->bv_len] = '\0'; + ber->ber_tag = *ber->ber_ptr; return tag; } @@ -499,6 +511,7 @@ ber_get_bitstringa( *buf = NULL; return LBER_DEFAULT; } + ber->ber_tag = *ber->ber_ptr; *blen = datalen * 8 - unusedbits; return tag; @@ -520,6 +533,7 @@ ber_get_null( BerElement *ber ) if ( len != 0 ) { return LBER_DEFAULT; } + ber->ber_tag = *ber->ber_ptr; return( tag ); } @@ -558,6 +572,7 @@ ber_first_element( *last = NULL; return LBER_DEFAULT; } + ber->ber_tag = *ber->ber_ptr; *last = ber->ber_ptr + *len; @@ -743,6 +758,7 @@ ber_scanf ( BerElement *ber, if ( (rc = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) break; ber->ber_ptr += len; + ber->ber_tag = *ber->ber_ptr; break; case '{': /* begin sequence */ diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c index 578f42be09..6cc1505c5a 100644 --- a/libraries/liblber/io.c +++ b/libraries/liblber/io.c @@ -594,7 +594,7 @@ fill_buffer: } if (ber->ber_buf==NULL) { - ber->ber_buf = (char *) LBER_MALLOC( ber->ber_len ); + ber->ber_buf = (char *) LBER_MALLOC( ber->ber_len + 1 ); if (ber->ber_buf==NULL) { return LBER_DEFAULT; } -- 2.39.5