ITS#8733 Allow a raw integer to be decoded from a berval

This commit is contained in:
Hallvard Furuseth 2017-06-23 10:56:49 +01:00 committed by Ondřej Kuzník
parent 62811e8f65
commit ff2d7cc798
2 changed files with 22 additions and 10 deletions

View File

@ -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,

View File

@ -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 );
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 );
tag = ber_skip_element( ber, &bv );
len = bv.bv_len;
if ( tag == LBER_DEFAULT || len > sizeof(ber_int_t) ) {
return LBER_DEFAULT;
}
/* 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