Diff for /libraries/liblber/decode.c between versions 1.5.2.4 and 1.5.2.4.2.2

version 1.5.2.4, 1998/12/31 19:32:05 version 1.5.2.4.2.2, 1999/01/23 21:05:03
Line 27 Line 27
   
 #include "lber.h"  #include "lber.h"
   
 #ifdef LDAP_DEBUG  
 int     lber_debug;  int     lber_debug;
 #endif  
   
 static int ber_getnint LDAP_P(( BerElement *ber, long *num, int len ));  static int ber_getnint LDAP_P(( BerElement *ber, long *num, int len ));
   
Line 228  ber_get_stringa( BerElement *ber, char * Line 226  ber_get_stringa( BerElement *ber, char *
 {  {
         unsigned long   datalen, tag;          unsigned long   datalen, tag;
   
         if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT )          if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
                   *buf = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
   
         if ( (*buf = (char *) malloc( (size_t)datalen + 1 )) == NULL )          if ( (*buf = (char *) malloc( (size_t)datalen + 1 )) == NULL )
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
   
         if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen )          if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen ) {
                   free( *buf );
                   *buf = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
         (*buf)[datalen] = '\0';          (*buf)[datalen] = '\0';
   
 #ifdef STR_TRANSLATION  #ifdef STR_TRANSLATION
Line 245  ber_get_stringa( BerElement *ber, char * Line 248  ber_get_stringa( BerElement *ber, char *
                 if ( (*(ber->ber_decode_translate_proc))( buf, &datalen, 1 )                  if ( (*(ber->ber_decode_translate_proc))( buf, &datalen, 1 )
                     != 0 ) {                      != 0 ) {
                         free( *buf );                          free( *buf );
                           *buf = NULL;
                         return( LBER_DEFAULT );                          return( LBER_DEFAULT );
                 }                  }
         }          }
Line 258  ber_get_stringal( BerElement *ber, struc Line 262  ber_get_stringal( BerElement *ber, struc
 {  {
         unsigned long   len, tag;          unsigned long   len, tag;
   
         if ( (*bv = (struct berval *) malloc( sizeof(struct berval) )) == NULL )          if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
                   *bv = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
   
         if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )          if ( (*bv = (struct berval *) malloc( sizeof(struct berval) )) == NULL )
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
   
         if ( ((*bv)->bv_val = (char *) malloc( (size_t)len + 1 )) == NULL )          if ( ((*bv)->bv_val = (char *) malloc( (size_t)len + 1 )) == NULL ) {
                   free( *bv );
                   *bv = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
   
         if ( (unsigned long) ber_read( ber, (*bv)->bv_val, len ) != len )          if ( (unsigned long) ber_read( ber, (*bv)->bv_val, len ) != len ) {
                   ber_bvfree( *bv );
                   *bv = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
         ((*bv)->bv_val)[len] = '\0';          ((*bv)->bv_val)[len] = '\0';
         (*bv)->bv_len = len;          (*bv)->bv_len = len;
   
Line 278  ber_get_stringal( BerElement *ber, struc Line 290  ber_get_stringal( BerElement *ber, struc
                 ++len;                  ++len;
                 if ( (*(ber->ber_decode_translate_proc))( &((*bv)->bv_val),                  if ( (*(ber->ber_decode_translate_proc))( &((*bv)->bv_val),
                     &len, 1 ) != 0 ) {                      &len, 1 ) != 0 ) {
                         free( (*bv)->bv_val );                          ber_bvfree( *bv );
                           *bv = NULL;
                         return( LBER_DEFAULT );                          return( LBER_DEFAULT );
                 }                  }
                 (*bv)->bv_len = len - 1;                  (*bv)->bv_len = len - 1;
Line 294  ber_get_bitstringa( BerElement *ber, cha Line 307  ber_get_bitstringa( BerElement *ber, cha
         unsigned long   datalen, tag;          unsigned long   datalen, tag;
         unsigned char   unusedbits;          unsigned char   unusedbits;
   
         if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT )          if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
                   *buf = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
         --datalen;          --datalen;
   
         if ( (*buf = (char *) malloc( (size_t)datalen )) == NULL )          if ( (*buf = (char *) malloc( (size_t)datalen )) == NULL )
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
   
         if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 )          if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
                   free( buf );
                   *buf = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
   
         if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen )          if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen ) {
                   free( buf );
                   *buf = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
           }
   
         *blen = datalen * 8 - unusedbits;          *blen = datalen * 8 - unusedbits;
         return( tag );          return( tag );
Line 342  ber_first_element( BerElement *ber, unsi Line 363  ber_first_element( BerElement *ber, unsi
 {  {
         /* skip the sequence header, use the len to mark where to stop */          /* skip the sequence header, use the len to mark where to stop */
         if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) {          if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) {
                   *last = NULL;
                 return( LBER_DEFAULT );                  return( LBER_DEFAULT );
         }          }
   
Line 379  va_dcl Line 401  va_dcl
         BerElement      *ber;          BerElement      *ber;
         char            *fmt;          char            *fmt;
 #endif  #endif
           char            *fmt_reset;
         char            *last;          char            *last;
         char            *s, **ss, ***sss;          char            *s, **ss, ***sss;
         struct berval   ***bv, **bvp, *bval;          struct berval   ***bv, **bvp, *bval;
Line 393  va_dcl Line 416  va_dcl
         ber = va_arg( ap, BerElement * );          ber = va_arg( ap, BerElement * );
         fmt = va_arg( ap, char * );          fmt = va_arg( ap, char * );
 #endif  #endif
           fmt_reset = fmt;
   
 #ifdef LDAP_DEBUG  #ifdef LDAP_DEBUG
         if ( lber_debug & 64 ) {          if ( lber_debug & 64 ) {
Line 402  va_dcl Line 426  va_dcl
 #endif  #endif
   
         for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) {          for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) {
                   /* When this is modified, remember to update
                    * the error-cleanup code below accordingly. */
                 switch ( *fmt ) {                  switch ( *fmt ) {
                 case 'a':       /* octet string - allocate storage as needed */                  case 'a':       /* octet string - allocate storage as needed */
                         ss = va_arg( ap, char ** );                          ss = va_arg( ap, char ** );
Line 530  va_dcl Line 556  va_dcl
   
         va_end( ap );          va_end( ap );
   
           if ( rc == LBER_DEFAULT ) {
               /*
                * Error.  Reclaim malloced memory that was given to the caller.
                * Set allocated pointers to NULL, "data length" outvalues to 0.
                */
   #ifdef HAVE_STDARG
               va_start( ap, fmt );
   #else
               va_start( ap );
               (void) va_arg( ap, BerElement * );
               (void) va_arg( ap, char * );
   #endif
   
               for ( ; fmt_reset < fmt; fmt_reset++ ) {
                   switch ( *fmt_reset ) {
                   case 'a':       /* octet string - allocate storage as needed */
                           ss = va_arg( ap, char ** );
                           if ( *ss ) {
                                   free( *ss );
                                   *ss = NULL;
                           }
                           break;
   
                   case 'b':       /* boolean */
                   case 't':       /* tag of next item */
                   case 'T':       /* skip tag of next item */
                           (void) va_arg( ap, int * );
                           break;
   
                   case 's':       /* octet string - in a buffer */
                           (void) va_arg( ap, char * );
                           /* Fall through */
                   case 'e':       /* enumerated */
                   case 'i':       /* int */
                   case 'l':       /* length of next item */
                           (void) va_arg( ap, long * );
                           break;
   
                   case 'o':       /* octet string in a supplied berval */
                           bval = va_arg( ap, struct berval * );
                           if ( bval->bv_val ) {
                                   free( bval->bv_val );
                                   bval->bv_val = NULL;
                           }
                           bval->bv_len = 0;
                           break;
   
                   case 'O':       /* octet string - allocate & include length */
                           bvp = va_arg( ap, struct berval ** );
                           if ( *bvp ) {
                                   ber_bvfree( *bvp );
                                   *bvp = NULL;
                           }
                           break;
   
                   case 'B':       /* bit string - allocate storage as needed */
                           ss = va_arg( ap, char ** );
                           if ( *ss ) {
                                   free( *ss );
                                   *ss = NULL;
                           }
                           *(va_arg( ap, long * )) = 0; /* for length, in bits */
                           break;
   
                   case 'v':       /* sequence of strings */
                           sss = va_arg( ap, char *** );
                           if ( *sss ) {
                                   for (j = 0;  (*sss)[j];  j++)
                                           free( (*sss)[j] );
                                   free( *sss );
                                   *sss = NULL;
                           }
                           break;
   
                   case 'V':       /* sequence of strings + lengths */
                           bv = va_arg( ap, struct berval *** );
                           if ( *bv ) {
                                   ber_bvecfree( *bv );
                                   *bv = NULL;
                           }
                           break;
   
   #if 0           /* No action for these format characters */
                   case 'n':       /* null */
                   case 'x':       /* skip the next element - whatever it is */
                   case '{':       /* begin sequence */
                   case '[':       /* begin set */
                   case '}':       /* end sequence */
                   case ']':       /* end set */
   #endif
   
                   }
               }
   
               va_end( ap );
           }
   
         return( rc );          return( rc );
 }  }
   

Removed from v.1.5.2.4  
changed lines
  Added in v.1.5.2.4.2.2


______________
© Copyright 1998-2020, OpenLDAP Foundation, info@OpenLDAP.org