#include "lber-int.h"
-static ber_slen_t BerRead LDAP_P((
- Sockbuf *sb,
- char *buf,
- ber_len_t len ));
-
#define EXBUFSIZ 1024
-/* probably far too large... */
-#define MAX_BERBUFSIZE (128*1024)
-
-#if defined( DOS ) && !defined( _WIN32 ) && (MAX_BERBUFSIZE > 65535)
-# undef MAX_BERBUFSIZE
-# define MAX_BERBUFSIZE 65535
-#endif
-
static ber_slen_t
BerRead(
Sockbuf *sb,
- char *buf,
+ unsigned char *buf,
ber_len_t len )
{
ber_slen_t c;
break;
return( c );
}
- buf+= c;
+ buf+=c;
nread+=c;
len-=c;
}
nleft = ber->ber_end - ber->ber_ptr;
actuallen = nleft < len ? nleft : len;
- SAFEMEMCPY( buf, ber->ber_ptr, actuallen );
+ AC_MEMCPY( buf, ber->ber_ptr, actuallen );
ber->ber_ptr += actuallen;
if ( ber_realloc( ber, len ) != 0 )
return( -1 );
}
- SAFEMEMCPY( ber->ber_ptr, buf, (size_t)len );
+ AC_MEMCPY( ber->ber_ptr, buf, (size_t)len );
ber->ber_ptr += len;
return( (ber_slen_t) len );
if ( ber_realloc( ber, len ) != 0 )
return( -1 );
}
- SAFEMEMCPY( ber->ber_sos->sos_ptr, buf, (size_t)len );
+ AC_MEMCPY( ber->ber_sos->sos_ptr, buf, (size_t)len );
ber->ber_sos->sos_ptr += len;
ber->ber_sos->sos_clen += len;
return( (ber_slen_t) len );
if ( sb->sb_debug ) {
ber_log_printf( LDAP_DEBUG_ANY, sb->sb_debug,
- "ber_flush: %ld bytes to sd %ld%s\n", towrite,
- (long) sb->sb_fd, ber->ber_rwptr != ber->ber_buf ?
- " (re-flush)" : "" );
+ "ber_flush: %ld bytes to sd %ld%s\n",
+ towrite, (long) sb->sb_fd,
+ ber->ber_rwptr != ber->ber_buf ? " (re-flush)" : "" );
ber_log_bprint( LDAP_DEBUG_PACKETS, sb->sb_debug,
ber->ber_rwptr, towrite );
}
if( ber == NULL ) {
/* allocation failed */
- return ( NULL );
+ return NULL;
}
/* copy the data */
- if ( ( (ber_len_t) ber_write ( ber, bv->bv_val, bv->bv_len, 0 )) != bv->bv_len ) {
+ if ( ((ber_len_t) ber_write ( ber, bv->bv_val, bv->bv_len, 0 ))
+ != bv->bv_len )
+ {
/* write failed, so free and return NULL */
ber_free( ber, 1 );
- return( NULL );
+ return NULL;
}
ber_reset( ber, 1 ); /* reset the pointer to the start of the buffer */
-
- return ( ber );
+ return ber;
}
/* New C-API ber_flatten routine */
ber_int_options.lbo_valid = LBER_INITIALIZED;
if(bvPtr == NULL) {
- return( -1 );
+ return -1;
}
- if ( (bv = LBER_MALLOC( sizeof(struct berval))) == NULL ) {
- return( -1 );
+ bv = LBER_MALLOC( sizeof(struct berval));
+ if ( bv == NULL ) {
+ return -1;
}
if ( ber == NULL ) {
/* copy the berval */
ber_len_t len = ber->ber_ptr - ber->ber_buf;
- if ( (bv->bv_val = (char *) LBER_MALLOC( len + 1 )) == NULL ) {
- ber_bvfree( bv );
- return( -1 );
+ bv->bv_val = (char *) LBER_MALLOC( len + 1 );
+ if ( bv->bv_val == NULL ) {
+ LBER_FREE( bv );
+ return -1;
}
- SAFEMEMCPY( bv->bv_val, ber->ber_buf, len );
+ AC_MEMCPY( bv->bv_val, ber->ber_buf, len );
bv->bv_val[len] = '\0';
bv->bv_len = len;
}
*bvPtr = bv;
- return( 0 );
+ return 0;
}
void
ber->ber_rwptr = NULL;
}
-#if 0
-/* return the tag - LBER_DEFAULT returned means trouble */
-static ber_tag_t
-get_tag( Sockbuf *sb )
-{
- unsigned char xbyte;
- ber_tag_t tag;
- char *tagp;
- unsigned int i;
-
- assert( sb != NULL );
- assert( SOCKBUF_VALID( sb ) );
-
- if ( ber_int_sb_read( sb, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
-
- if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK )
- return( (ber_tag_t) xbyte );
-
- tagp = (char *) &tag;
- tagp[0] = xbyte;
- for ( i = 1; i < sizeof(ber_tag_t); i++ ) {
- if ( ber_int_sb_read( sb, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
-
- tagp[i] = xbyte;
-
- if ( ! (xbyte & LBER_MORE_TAG_MASK) )
- break;
- }
-
- /* tag too big! */
- if ( i == sizeof(ber_tag_t) )
- return( LBER_DEFAULT );
-
- /* want leading, not trailing 0's */
- return( tag >> (sizeof(ber_tag_t) - i - 1) );
-}
-#endif
-
/*
* A rewrite of ber_get_next that can safely be called multiple times
* for the same packet. It will simply continue where it stopped until
}
do {
/* reading the tag... */
- if (ber_int_sb_read( sb, ber->ber_rwptr, 1)<=0)
+ if (ber_int_sb_read( sb, ber->ber_rwptr, 1)<=0) {
return LBER_DEFAULT;
+ }
+
if (! (ber->ber_rwptr[0] & LBER_MORE_TAG_MASK) ) {
ber->ber_tag>>=sizeof(ber->ber_tag) -
((char *) &ber->ber_tag - ber->ber_rwptr);
goto get_lenbyte;
}
} while( PTR_IN_VAR(ber->ber_rwptr, ber->ber_tag ));
+
errno = ERANGE; /* this is a serious error. */
return LBER_DEFAULT;
}
fill_buffer:
/* now fill the buffer. */
if (ber->ber_buf==NULL) {
- if (ber->ber_len > MAX_BERBUFSIZE) {
- errno = ERANGE;
- return LBER_DEFAULT;
- }
ber->ber_buf = (char *) LBER_MALLOC( ber->ber_len );
- if (ber->ber_buf==NULL)
+ if (ber->ber_buf==NULL) {
return LBER_DEFAULT;
+ }
ber->ber_rwptr = ber->ber_buf;
ber->ber_ptr = ber->ber_buf;
ber->ber_end = ber->ber_buf + ber->ber_len;