*len = lc;
}
+ /* BER element should have enough data left */
+ if( *len > ber_pvt_ber_remaining( ber ) ) {
+ return LBER_DEFAULT;
+ }
+
return tag;
}
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
- if ( datalen > (*len - 1) ) {
+
+ /* must fit within allocated space with termination */
+ if ( datalen >= *len ) {
return LBER_DEFAULT;
}
assert( BER_VALID( ber ) );
- nleft = ber->ber_end - ber->ber_ptr;
+ nleft = ber_pvt_ber_remaining( ber );
actuallen = nleft < len ? nleft : len;
AC_MEMCPY( buf, ber->ber_ptr, actuallen );