line[ off ] = hexdig[ 0x0f & ( data[i] >> 4 ) ];
line[ off+1 ] = hexdig[ 0x0f & data[i] ];
- off = BP_GRAPH + n;
+ off = BP_GRAPH + n + ((n >= 8)?1:0);
if ( isprint( data[i] )) {
line[ BP_GRAPH + n ] = data[i];
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
+ if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
+ return LBER_DEFAULT;
+ }
tag = xbyte;
- if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK )
+ if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) {
return tag;
+ }
for ( i = 1; i < sizeof(ber_tag_t); i++ ) {
- if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
+ if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
+ return LBER_DEFAULT;
+ }
tag <<= 8;
tag |= 0x00ffUL & (ber_tag_t) xbyte;
- if ( ! (xbyte & LBER_MORE_TAG_MASK) )
+ if ( ! (xbyte & LBER_MORE_TAG_MASK) ) {
break;
+ }
}
/* tag too big! */
- if ( i == sizeof(ber_tag_t) )
- return( LBER_DEFAULT );
+ if ( i == sizeof(ber_tag_t) ) {
+ return LBER_DEFAULT;
+ }
return tag;
}
* First, we read the tag.
*/
- if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
/*
* Next, read the length. The first byte contains the length of
*/
if ( ber_read( ber, (char *) &lc, 1 ) != 1 )
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
if ( lc & 0x80U ) {
noctets = (lc & 0x7fU);
if ( noctets > sizeof(ber_len_t) ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
if( (unsigned) ber_read( ber, netlen, noctets ) != noctets ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
for( i = 0; i < noctets; i++ ) {
*len = lc;
}
- return( tag );
+ return tag;
}
ber_tag_t
assert( ber != NULL );
assert( num != NULL );
-
assert( BER_VALID( ber ) );
/*
* extend after we read it in.
*/
- if ( len > sizeof(ber_int_t) )
- return( -1 );
+ if ( len > sizeof(ber_int_t) ) {
+ return -1;
+ }
/* read into the low-order bytes of our buffer */
if ( (ber_len_t) ber_read( ber, (char *) buf, len ) != len ) {
- return( -1 );
+ return -1;
}
if( len ) {
*num = 0;
}
- return( len );
+ return len;
}
ber_tag_t
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
- if ( ber_getnint( ber, num, len ) != len )
- return( LBER_DEFAULT );
- else
- return( tag );
+ if ( ber_getnint( ber, num, len ) != len ) {
+ return LBER_DEFAULT;
+ }
+
+ return tag;
}
ber_tag_t
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
- if ( datalen > (*len - 1) )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
+ if ( datalen > (*len - 1) ) {
+ return LBER_DEFAULT;
+ }
- if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen )
- return( LBER_DEFAULT );
+ if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen ) {
+ return LBER_DEFAULT;
+ }
buf[datalen] = '\0';
*len = datalen;
- return( tag );
+ return tag;
}
ber_tag_t
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- if ( (*buf = (char *) LBER_MALLOC( datalen + 1 )) == NULL )
- return( LBER_DEFAULT );
+ if ( (*buf = (char *) LBER_MALLOC( datalen + 1 )) == NULL ) {
+ return LBER_DEFAULT;
+ }
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( *buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
(*buf)[datalen] = '\0';
- return( tag );
+ return tag;
}
ber_tag_t
((*bv)->bv_val)[len] = '\0';
(*bv)->bv_len = len;
- return( tag );
+ return tag;
}
ber_tag_t
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
--datalen;
- if ( (*buf = (char *) LBER_MALLOC( datalen )) == NULL )
- return( LBER_DEFAULT );
+ if ( (*buf = (char *) LBER_MALLOC( datalen )) == NULL ) {
+ return LBER_DEFAULT;
+ }
if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
LBER_FREE( buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
*blen = datalen * 8 - unusedbits;
- return( tag );
+ return tag;
}
ber_tag_t
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
- if ( len != 0 )
- return( LBER_DEFAULT );
+ if ( len != 0 ) {
+ return LBER_DEFAULT;
+ }
return( tag );
}
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
- return( rc );
+ return rc;
}
ber_tag_t
/* skip the sequence header, use the len to mark where to stop */
if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) {
*last = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
*last = ber->ber_ptr + *len;
if ( *last == ber->ber_ptr ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- return( ber_peek_tag( ber, len ) );
+ return ber_peek_tag( ber, len );
}
ber_tag_t
assert( BER_VALID( ber ) );
if ( ber->ber_ptr == last ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- return( ber_peek_tag( ber, len ) );
+ return ber_peek_tag( ber, len );
}
/* VARARGS */
va_end( ap );
}
- return( rc );
+ return rc;
}
for ( i = sizeof(ber_tag_t) - 1; i > 0; i-- ) {
mask = ((ber_tag_t)0xffU << (i * 8));
/* not all zero */
- if ( tag & mask )
- break;
+ if ( tag & mask ) break;
}
- return( i + 1 );
+ return i + 1;
}
static int
*/
if ( len <= (ber_len_t) 0x7FU )
- return( 1 );
+ return 1;
/*
* long len otherwise - one byte with bit 8 set, giving the
*/
if ( len <= (ber_len_t) 0xffU )
- return( 2 );
+ return 2;
if ( len <= (ber_len_t) 0xffffU )
- return( 3 );
+ return 3;
if ( len <= (ber_len_t) 0xffffffU )
- return( 4 );
+ return 4;
- return( 5 );
+ return 5;
}
static int
if ( len <= 127 ) {
char length_byte = (char) len;
- return( ber_write( ber, &length_byte, 1, nosos ) );
+ return ber_write( ber, &length_byte, 1, nosos );
}
/*
for ( i = sizeof(ber_len_t) - 1; i > 0; i-- ) {
mask = ((ber_len_t)0xffU << (i * 8));
/* not all zero */
- if ( len & mask )
- break;
+ if ( len & mask ) break;
}
lenlen = (unsigned char) ++i;
if ( lenlen > 4 )
- return( -1 );
+ return -1;
lenlen |= 0x80UL;
/* write the length of the length */
if ( ber_write( ber, &lenlen, 1, nosos ) != 1 )
- return( -1 );
+ return -1;
for( j=0; j<i; j++) {
netlen[(sizeof(ber_len_t)-1) - j] = (unsigned char)(len & 0xffU);
if ( sign ) {
/* not all ones */
- if ( (unum & mask) != mask )
- break;
+ if ( (unum & mask) != mask ) break;
} else {
/* not all zero */
- if ( unum & mask )
- break;
+ if ( unum & mask ) break;
}
}
* byte matches the sign bit, we need to "back up" a byte.
*/
mask = (unum & ((ber_uint_t)0x80U << (i * 8)));
- if ( (mask && !sign) || (sign && !mask) )
+ if ( (mask && !sign) || (sign && !mask) ) {
i++;
+ }
len = i + 1;
- if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 )
- return( -1 );
+ if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) {
+ return -1;
+ }
if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 )
- return( -1 );
+ return -1;
i++;
for( j=0; j<i; j++ ) {
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_ENUMERATED;
+ }
- return( ber_put_int_or_enum( ber, num, tag ) );
+ return ber_put_int_or_enum( ber, num, tag );
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_INTEGER;
+ }
- return( ber_put_int_or_enum( ber, num, tag ) );
+ return ber_put_int_or_enum( ber, num, tag );
}
int
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_OCTETSTRING;
+ }
if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 )
- return( -1 );
+ return -1;
if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 ||
(ber_len_t) ber_write( ber, str, len, 0 ) != len ) {
rc = taglen + lenlen + len;
}
- return( rc );
+ return rc;
}
int
assert( BER_VALID( ber ) );
- return( ber_put_ostring( ber, str, strlen( str ), tag ));
+ return ber_put_ostring( ber, str, strlen( str ), tag );
}
int
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_BITSTRING;
+ }
- if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 )
- return( -1 );
+ if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) {
+ return -1;
+ }
len = ( blen + 7 ) / 8;
unusedbits = (unsigned char) ((len * 8) - blen);
- if ( (lenlen = ber_put_len( ber, len + 1, 0 )) == -1 )
- return( -1 );
+ if ( (lenlen = ber_put_len( ber, len + 1, 0 )) == -1 ) {
+ return -1;
+ }
- if ( ber_write( ber, (char *)&unusedbits, 1, 0 ) != 1 )
- return( -1 );
+ if ( ber_write( ber, (char *)&unusedbits, 1, 0 ) != 1 ) {
+ return -1;
+ }
- if ( (ber_len_t) ber_write( ber, str, len, 0 ) != len )
- return( -1 );
+ if ( (ber_len_t) ber_write( ber, str, len, 0 ) != len ) {
+ return -1;
+ }
/* return length of tag + length + unused bit count + contents */
- return( taglen + 1 + lenlen + len );
+ return taglen + 1 + lenlen + len;
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_NULL;
+ }
- if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 )
- return( -1 );
+ if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) {
+ return -1;
+ }
- if ( ber_put_len( ber, 0, 0 ) != 1 )
- return( -1 );
+ if ( ber_put_len( ber, 0, 0 ) != 1 ) {
+ return -1;
+ }
- return( taglen + 1 );
+ return taglen + 1;
}
int
if ( tag == LBER_DEFAULT )
tag = LBER_BOOLEAN;
- if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 )
- return( -1 );
+ if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) {
+ return -1;
+ }
- if ( ber_put_len( ber, 1, 0 ) != 1 )
- return( -1 );
+ if ( ber_put_len( ber, 1, 0 ) != 1 ) {
+ return -1;
+ }
if ( ber_write( ber, (char *)(boolval ? &trueval : &falseval), 1, 0 )
- != 1 )
- return( -1 );
+ != 1 )
+ {
+ return -1;
+ }
- return( taglen + 2 );
+ return taglen + 2;
}
#define FOUR_BYTE_LEN 5
new = (Seqorset *) LBER_CALLOC( 1, sizeof(Seqorset) );
- if ( new == NULL )
- return( -1 );
+ if ( new == NULL ) {
+ return -1;
+ }
new->sos_ber = ber;
- if ( ber->ber_sos == NULL )
+ if ( ber->ber_sos == NULL ) {
new->sos_first = ber->ber_ptr;
- else
+ } else {
new->sos_first = ber->ber_sos->sos_ptr;
+ }
/* Set aside room for a 4 byte length field */
new->sos_ptr = new->sos_first + ber_calc_taglen( tag ) + FOUR_BYTE_LEN;
new->sos_next = ber->ber_sos;
ber->ber_sos = new;
- return( 0 );
+ return 0;
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_SEQUENCE;
+ }
- return( ber_start_seqorset( ber, tag ) );
+ return ber_start_seqorset( ber, tag );
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( tag == LBER_DEFAULT )
+ if ( tag == LBER_DEFAULT ) {
tag = LBER_SET;
+ }
- return( ber_start_seqorset( ber, tag ) );
+ return ber_start_seqorset( ber, tag );
}
static int
len = (*sos)->sos_clen;
- if ( sizeof(ber_len_t) > 4 && len > 0xffffffffUL )
- return( -1 );
+ if ( sizeof(ber_len_t) > 4 && len > 0xffffffffUL ) {
+ return -1;
+ }
if ( ber->ber_options & LBER_USE_DER ) {
lenlen = ber_calc_lenlen( len );
if ( ber->ber_options & LBER_USE_DER ) {
/* Write the length in the minimum # of octets */
- if ( ber_put_len( ber, len, 1 ) == -1 )
- return( -1 );
+ if ( ber_put_len( ber, len, 1 ) == -1 ) {
+ return -1;
+ }
if (lenlen != FOUR_BYTE_LEN) {
/*
} else {
/* Fill FOUR_BYTE_LEN bytes for length field */
/* one byte of length length */
- if ( ber_write( ber, (char *)<ag, 1, 1 ) != 1 )
- return( -1 );
+ if ( ber_write( ber, (char *)<ag, 1, 1 ) != 1 ) {
+ return -1;
+ }
/* the length itself */
rc = ber_write( ber,
FOUR_BYTE_LEN-1, 1 );
if( rc != FOUR_BYTE_LEN - 1 ) {
- return( -1 );
+ return -1;
}
}
/* The ber_ptr is at the set/seq start - move it to the end */
LBER_FREE( (char *) (*sos) );
*sos = next;
- return( taglen + lenlen + len );
+ return taglen + lenlen + len;
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- return( ber_put_seqorset( ber ) );
+ return ber_put_seqorset( ber );
}
int
assert( ber != NULL );
assert( BER_VALID( ber ) );
- return( ber_put_seqorset( ber ) );
+ return ber_put_seqorset( ber );
}
/* N tag */
va_end( ap );
- return( rc );
+ return rc;
}
#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,
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;
}
AC_MEMCPY( bv->bv_val, ber->ber_buf, 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
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;
mh->bm_sequence, mh, mh->bm_length, ber_int_options.lbo_meminuse);
#endif
/* Fill the free space with poison */
- memset( mh, 0xff, mh->bm_length + sizeof(struct ber_mem_hdr) + sizeof( ber_int_t));
+ memset( mh, 0xff, mh->bm_length + sizeof(struct ber_mem_hdr) + sizeof(ber_int_t));
free( mh );
#else
free( p );
BER_MEM_VALID( bv );
- if ( bv->bv_val != NULL )
+ if ( bv->bv_val != NULL ) {
LBER_FREE( bv->bv_val );
+ }
LBER_FREE( (char *) bv );
}
BER_MEM_VALID( bv );
- for ( i = 0; bv[i] != NULL; i++ )
+ for ( i = 0; bv[i] != NULL; i++ ) {
ber_bvfree( bv[i] );
+ }
LBER_FREE( (char *) bv );
}
new->bv_val[bv->bv_len] = '\0';
new->bv_len = bv->bv_len;
- return( new );
+ return new;
}
struct berval *
LBER_FREE( p );
}
- return( new );
+ return new;
}
char *
if( s == NULL ) {
ber_errno = LBER_ERROR_PARAM;
- return( NULL );
+ return NULL;
}
len = strlen( s ) + 1;
if ( (p = LBER_MALLOC( len )) == NULL ) {
ber_errno = LBER_ERROR_MEMORY;
- return( NULL );
+ return NULL;
}
AC_MEMCPY( p, s, len );
- return( p );
+ return p;
}
{
Sockbuf_IO_Desc *p;
int ret = 0;
- char buf[4096];
assert( sb != NULL );
ret = ber_pvt_socket_set_nonblock( sb->sb_fd, arg != NULL)
? -1 : 1;
break;
- case LBER_SB_OPT_DRAIN:
- /* Drain the data source to enable possible errors (e.g.
- * TLS) to be propagated to the upper layers
- */
- do {
- ret = ber_int_sb_read( sb, buf, sizeof( buf ) );
- } while ( ret == sizeof( buf ) );
+ case LBER_SB_OPT_DRAIN: {
+ /* Drain the data source to enable possible errors (e.g.
+ * TLS) to be propagated to the upper layers
+ */
+ char buf[MIN_BUFF_SIZE];
+ do {
+ ret = ber_int_sb_read( sb, buf, sizeof( buf ) );
+ } while ( ret == sizeof( buf ) );
- ret = 1;
- break;
+ ret = 1;
+ } break;
case LBER_SB_OPT_NEEDS_READ:
ret = ( sb->sb_trans_needs_read ? 1 : 0 );
break;