/* encode.c - ber output encoding routines */
/* $OpenLDAP$ */
/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
#include <ac/socket.h>
#include <ac/string.h>
-#undef LDAP_F_PRE
-#define LDAP_F_PRE LDAP_F_EXPORT
-
#include "lber-int.h"
static int ber_put_len LDAP_P((
#ifdef STR_TRANSLATION
if ( len > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0 &&
ber->ber_encode_translate_proc ) {
- if ( (*(ber->ber_encode_translate_proc))( &str, &len, 0 )
- != 0 ) {
+ if ( (*(ber->ber_encode_translate_proc))( &str, &len, 0 ) != 0 ) {
return( -1 );
}
free_str = 1;
ber_tag_t tag )
{
ber_len_t taglen;
- unsigned char trueval = 0xFFU;
- unsigned char falseval = 0x00U;
+ unsigned char trueval = (unsigned char) -1;
+ unsigned char falseval = 0;
assert( ber != NULL );
assert( BER_VALID( ber ) );
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 );