From: Hallvard Furuseth Date: Fri, 23 Jun 2017 09:56:49 +0000 (+0100) Subject: ITS#8733 Allow a raw integer to be decoded from a berval X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ff2d7cc798897ddcd53ed453a7f4ae2442facd71;p=openldap ITS#8733 Allow a raw integer to be decoded from a berval --- diff --git a/include/lber.h b/include/lber.h index e0ea43d4aa..d2adde423b 100644 --- a/include/lber.h +++ b/include/lber.h @@ -280,6 +280,11 @@ ber_get_enum LDAP_P(( BerElement *ber, ber_int_t *num )); +LBER_F( int ) +ber_decode_int LDAP_P(( + const struct berval *bv, + ber_int_t *num )); + LBER_F( ber_tag_t ) ber_get_stringb LDAP_P(( BerElement *ber, diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index 7de08229f8..0e30a572b8 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -283,21 +283,28 @@ ber_get_int( BerElement *ber, ber_int_t *num ) { - ber_tag_t tag; - ber_len_t len; struct berval bv; + ber_tag_t tag = ber_skip_element( ber, &bv ); - assert( num != NULL ); - - tag = ber_skip_element( ber, &bv ); - len = bv.bv_len; - if ( tag == LBER_DEFAULT || len > sizeof(ber_int_t) ) { - return LBER_DEFAULT; + if ( tag == LBER_DEFAULT ) { + return tag; } + return ber_decode_int( &bv, num ) ? LBER_DEFAULT : tag; +} + +int +ber_decode_int( const struct berval *bv, ber_int_t *num ) +{ + ber_len_t len = bv->bv_len; + if ( len > sizeof(ber_int_t) ) + return -1; + + assert( num != NULL ); + /* parse two's complement integer */ if( len ) { - unsigned char *buf = (unsigned char *) bv.bv_val; + unsigned char *buf = (unsigned char *) bv->bv_val; ber_len_t i; ber_int_t netnum = buf[0] & 0xff; @@ -315,7 +322,7 @@ ber_get_int( *num = 0; } - return tag; + return 0; } ber_tag_t