]> git.sur5r.net Git - openldap/commitdiff
ITS#8733 Allow a raw integer to be decoded from a berval
authorHallvard Furuseth <hallvard@openldap.org>
Fri, 23 Jun 2017 09:56:49 +0000 (10:56 +0100)
committerOndřej Kuzník <ondra@mistotebe.net>
Thu, 28 Sep 2017 13:15:06 +0000 (14:15 +0100)
include/lber.h
libraries/liblber/decode.c

index e0ea43d4aaac2fca1fbb3c38a80c9a6c6c5c995b..d2adde423ba6ee2c8aa7a15a54775f11c7790f3e 100644 (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,
index 7de08229f87872c7b3c9720e6bfd4e7b87f7b8e8..0e30a572b80c01e4ab7428e3943b4256c1c65b87 100644 (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 );
 
-       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