]> git.sur5r.net Git - openldap/blobdiff - libraries/liblber/encode.c
Move schema needed by slapd to core.schema so that only one file
[openldap] / libraries / liblber / encode.c
index 3003ddb3300357e97ec02f3fd45bd2eb0de1bd3a..6ad945d6495682a73078918c22b7dfaac08d0206 100644 (file)
@@ -1,7 +1,7 @@
 /* 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
@@ -26,9 +26,6 @@
 #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((
@@ -418,8 +415,8 @@ ber_put_boolean(
        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 ) );
@@ -584,6 +581,21 @@ ber_put_seqorset( BerElement *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 );