- (*sos)->sos_ber->ber_ptr += len;
-
- } else {
- int i;
- unsigned char nettag[sizeof(ber_tag_t)];
- ber_tag_t tmptag = (*sos)->sos_tag;
-
- if( ber->ber_sos->sos_ptr > ber->ber_end ) {
- /* The sos_ptr exceeds the end of the BerElement
- * this can happen, for example, when the sos_ptr
- * is near the end and no data was written for the
- * 'V'. We must realloc the BerElement to ensure
- * we don't overwrite the buffer when writing
- * the tag and length fields.
- */
- ber_len_t ext = ber->ber_sos->sos_ptr - ber->ber_end;
-
- if( ber_realloc( ber, ext ) != 0 ) {
- return -1;
- }
- }
-
- /* the tag */
- taglen = ber_calc_taglen( tmptag );
-
- for( i = taglen-1; i >= 0; i-- ) {
- nettag[i] = (unsigned char)(tmptag & 0xffU);
- tmptag >>= 8;
- }
-
- AC_FMEMCPY( (*sos)->sos_first, nettag, taglen );
-
- if ( ber->ber_options & LBER_USE_DER ) {
- ltag = (lenlen == 1)
- ? (unsigned char) len
- : (unsigned char) (0x80U + (lenlen - 1));
- }
-
- /* one byte of length length */
- (*sos)->sos_first[1] = ltag;
-
- if ( ber->ber_options & LBER_USE_DER ) {
- if (lenlen > 1) {
- /* Write the length itself */
- AC_FMEMCPY( (*sos)->sos_first + 2, netlen, lenlen - 1 );
- }
- if (lenlen != FOUR_BYTE_LEN) {
- /*
- * We set aside FOUR_BYTE_LEN bytes for
- * the length field. Move the data if
- * we don't actually need that much
- */
- AC_FMEMCPY( (*sos)->sos_first + taglen +
- lenlen, (*sos)->sos_first + taglen +
- FOUR_BYTE_LEN, len );
- }
- } else {
- /* the length itself */
- AC_FMEMCPY( (*sos)->sos_first + taglen + 1,
- netlen, FOUR_BYTE_LEN - 1 );
- }
-
- next->sos_clen += (taglen + lenlen + len);
- next->sos_ptr += (taglen + lenlen + len);