From: Kurt Zeilenga Date: Fri, 26 Nov 1999 23:32:18 +0000 (+0000) Subject: Remove LBER_{TAG,INT,LEN}_{NTOH,HTON} macros. Rewrite code to X-Git-Tag: UCDATA_2_4~163 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8b99e6cdbd7c4517a6576877374ff52da55165a9;p=openldap Remove LBER_{TAG,INT,LEN}_{NTOH,HTON} macros. Rewrite code to manual push bytes about. Allows ber_*_t to be any 32-bit or larger type. Reworked AC_{HTON,NTOH}{L,S} macros to care only about 32-bit (netlong) and 16-bit (netshort) reordering as needed for BSD socket interface. --- diff --git a/configure b/configure index b7faf1042f..ec6fe0f686 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # $OpenLDAP$ -# from OpenLDAP: pkg/ldap/configure.in,v 1.280 1999/11/25 16:10:51 kdz Exp +# from OpenLDAP: pkg/ldap/configure.in,v 1.279 1999/11/17 01:26:55 kdz Exp # Copyright 1998,1999 The OpenLDAP Foundation. All Rights Reserved. # @@ -14052,14 +14052,20 @@ EOF -if test "$ac_cv_sizeof_long" -lt 4 ; then - { echo "configure: error: sizeof(long) < 4" 1>&2; exit 1; } -fi +if test "$ac_cv_sizeof_int" -lt 4 ; then + echo "configure: warning: OpenLDAP requires 'int' to be 32 bits or greater." 1>&2 -cat >> confdefs.h <<\EOF + cat >> confdefs.h <<\EOF #define LBER_INT_T long EOF +else + cat >> confdefs.h <<\EOF +#define LBER_INT_T int +EOF + +fi + cat >> confdefs.h <<\EOF #define LBER_LEN_T long EOF @@ -14074,7 +14080,7 @@ EOF echo $ac_n "checking for 8-bit clean memcmp""... $ac_c" 1>&6 -echo "configure:14078: checking for 8-bit clean memcmp" >&5 +echo "configure:14084: checking for 8-bit clean memcmp" >&5 if eval "test \"\${ac_cv_func_memcmp_clean+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -14082,7 +14088,7 @@ else ac_cv_func_memcmp_clean=no else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:14102: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_func_memcmp_clean=yes else @@ -14110,12 +14116,12 @@ echo "$ac_t""$ac_cv_func_memcmp_clean" 1>&6 test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.${ac_objext}" echo $ac_n "checking for strftime""... $ac_c" 1>&6 -echo "configure:14114: checking for strftime" >&5 +echo "configure:14120: checking for strftime" >&5 if eval "test \"\${ac_cv_func_strftime+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14149: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_strftime=yes" else @@ -14161,7 +14167,7 @@ else echo "$ac_t""no" 1>&6 # strftime is in -lintl on SCO UNIX. echo $ac_n "checking for strftime in -lintl""... $ac_c" 1>&6 -echo "configure:14165: checking for strftime in -lintl" >&5 +echo "configure:14171: checking for strftime in -lintl" >&5 ac_lib_var=`echo intl'_'strftime | sed 'y%./+-:%__p__%'` if eval "test \"\${ac_cv_lib_$ac_lib_var+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -14169,7 +14175,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lintl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14190: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -14208,12 +14214,12 @@ fi echo $ac_n "checking for inet_aton()""... $ac_c" 1>&6 -echo "configure:14212: checking for inet_aton()" >&5 +echo "configure:14218: checking for inet_aton()" >&5 if eval "test \"\${ol_cv_func_inet_aton+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14245: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ol_cv_func_inet_aton=yes else @@ -14257,12 +14263,12 @@ EOF echo $ac_n "checking for _spawnlp""... $ac_c" 1>&6 -echo "configure:14261: checking for _spawnlp" >&5 +echo "configure:14267: checking for _spawnlp" >&5 if eval "test \"\${ac_cv_func__spawnlp+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14296: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__spawnlp=yes" else @@ -14310,12 +14316,12 @@ fi echo $ac_n "checking for _snprintf""... $ac_c" 1>&6 -echo "configure:14314: checking for _snprintf" >&5 +echo "configure:14320: checking for _snprintf" >&5 if eval "test \"\${ac_cv_func__snprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14349: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__snprintf=yes" else @@ -14365,12 +14371,12 @@ fi echo $ac_n "checking for _vsnprintf""... $ac_c" 1>&6 -echo "configure:14369: checking for _vsnprintf" >&5 +echo "configure:14375: checking for _vsnprintf" >&5 if eval "test \"\${ac_cv_func__vsnprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14404: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__vsnprintf=yes" else @@ -14420,12 +14426,12 @@ fi echo $ac_n "checking for vprintf""... $ac_c" 1>&6 -echo "configure:14424: checking for vprintf" >&5 +echo "configure:14430: checking for vprintf" >&5 if eval "test \"\${ac_cv_func_vprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14459: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_vprintf=yes" else @@ -14473,12 +14479,12 @@ fi if test "$ac_cv_func_vprintf" != yes; then echo $ac_n "checking for _doprnt""... $ac_c" 1>&6 -echo "configure:14477: checking for _doprnt" >&5 +echo "configure:14483: checking for _doprnt" >&5 if eval "test \"\${ac_cv_func__doprnt+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14512: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__doprnt=yes" else @@ -14531,12 +14537,12 @@ if test $ac_cv_func_vprintf = yes ; then for ac_func in vsnprintf vsprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14535: checking for $ac_func" >&5 +echo "configure:14541: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14570: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14637,12 +14643,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14641: checking for $ac_func" >&5 +echo "configure:14647: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14676: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14694,12 +14700,12 @@ done for ac_func in getopt tempnam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14698: checking for $ac_func" >&5 +echo "configure:14704: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14733: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14760,13 +14766,13 @@ fi # Check Configuration echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 -echo "configure:14764: checking declaration of sys_errlist" >&5 +echo "configure:14770: checking declaration of sys_errlist" >&5 if eval "test \"\${ol_cv_dcl_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -14779,7 +14785,7 @@ int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:14783: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:14789: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_dcl_sys_errlist=yes ol_cv_have_sys_errlist=yes @@ -14802,20 +14808,20 @@ EOF echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 -echo "configure:14806: checking existence of sys_errlist" >&5 +echo "configure:14812: checking existence of sys_errlist" >&5 if eval "test \"\${ol_cv_have_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:14819: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14825: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ol_cv_have_sys_errlist=yes else diff --git a/configure.in b/configure.in index cf0379d18e..8b4439f8ed 100644 --- a/configure.in +++ b/configure.in @@ -1943,11 +1943,14 @@ AC_COMPILE_CHECK_SIZEOF(short) AC_COMPILE_CHECK_SIZEOF(int) AC_COMPILE_CHECK_SIZEOF(long) -if test "$ac_cv_sizeof_long" -lt 4 ; then - AC_MSG_ERROR([sizeof(long) < 4]) +if test "$ac_cv_sizeof_int" -lt 4 ; then + AC_MSG_WARN([OpenLDAP requires 'int' to be 32 bits or greater.]) + + AC_DEFINE(LBER_INT_T,long) +else + AC_DEFINE(LBER_INT_T,int) fi -AC_DEFINE(LBER_INT_T,long) AC_DEFINE(LBER_LEN_T,long) AC_DEFINE(LBER_SOCKET_T,int) AC_DEFINE(LBER_TAG_T,long) diff --git a/include/ac/socket.h b/include/ac/socket.h index 1d9d1840f3..4847dcb9c2 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -144,26 +144,14 @@ LDAP_F( int ) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * )); #if defined(__WIN32) && defined(_ALPHA) /* NT on Alpha is hosed. */ -#define AC_HTONL( l ) \ - ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \ - (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24)) -#define AC_NTOHL(l) AC_HTONL(l) - -#elif defined(__alpha) && !defined(VMS) -/* - * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the - * lower-order 32-bits of a (64-bit) long, so we define correct versions - * here. - */ -#define AC_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \ - | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 )) - -#define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \ - | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 )) +# define AC_HTONL( l ) \ + ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \ + (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24)) +# define AC_NTOHL(l) AC_HTONL(l) #else -#define AC_HTONL( l ) htonl( l ) -#define AC_NTOHL( l ) ntohl( l ) +# define AC_HTONL( l ) htonl( l ) +# define AC_NTOHL( l ) ntohl( l ) #endif /* htons()/ntohs() may be broken much like htonl()/ntohl() */ diff --git a/include/lber_types.nt b/include/lber_types.nt index 9bff7ccd75..c1280ec520 100644 --- a/include/lber_types.nt +++ b/include/lber_types.nt @@ -26,7 +26,7 @@ LDAP_BEGIN_DECL * * bitsof(short) == 2 * bitsof(int) == 4 - * bitsof(long) == 4 + * bitsof(long) == 4 /* or larger */ * * typedef unsigned int size_t; * typedef unsigned int SOCKET; @@ -35,7 +35,7 @@ LDAP_BEGIN_DECL */ /* LBER boolean, enum, integers - 32 bits or larger*/ -#define LBER_INT_T long +#define LBER_INT_T int /* LBER tags - 32 bits or larger */ #define LBER_TAG_T long diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index f150e756fd..4af3a38d51 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -79,9 +79,8 @@ ber_skip_tag( BerElement *ber, ber_len_t *len ) { ber_tag_t tag; unsigned char lc; - ber_len_t noctets; - int diff; - ber_len_t netlen; + ber_len_t i, noctets; + unsigned char netlen[sizeof(ber_len_t)]; assert( ber != NULL ); assert( len != NULL ); @@ -111,18 +110,27 @@ ber_skip_tag( BerElement *ber, ber_len_t *len ) * greater than what we can hold in a ber_len_t. */ - *len = netlen = 0; + *len = 0; + if ( ber_read( ber, (char *) &lc, 1 ) != 1 ) return( LBER_DEFAULT ); + if ( lc & 0x80U ) { noctets = (lc & 0x7fU); - if ( noctets > sizeof(ber_len_t) ) + + if ( noctets > sizeof(ber_len_t) ) { return( LBER_DEFAULT ); - diff = sizeof(ber_len_t) - noctets; - if ( (unsigned) ber_read( ber, (char *) &netlen + diff, noctets ) - != noctets ) + } + + if( (unsigned) ber_read( ber, netlen, noctets ) != noctets ) { return( LBER_DEFAULT ); - *len = LBER_LEN_NTOH( netlen ); + } + + for( i = 0; i < noctets; i++ ) { + *len <<= 8; + *len |= netlen[i]; + } + } else { *len = lc; } diff --git a/libraries/liblber/encode.c b/libraries/liblber/encode.c index a24bee2088..8d660eb457 100644 --- a/libraries/liblber/encode.c +++ b/libraries/liblber/encode.c @@ -73,17 +73,22 @@ ber_put_tag( { int rc; ber_len_t taglen; - ber_tag_t ntag; + ber_len_t i; + unsigned char nettag[sizeof(ber_tag_t)]; + ber_tag_t xtag; assert( ber != NULL ); assert( BER_VALID( ber ) ); taglen = ber_calc_taglen( tag ); - ntag = LBER_TAG_HTON( tag ); + for( i=0; i>= 8; + } rc = ber_write( ber, - ((char *) &ntag) + sizeof(ber_tag_t) - taglen, + &nettag[sizeof(ber_tag_t) - taglen], taglen, nosos ); return rc; @@ -118,10 +123,12 @@ ber_calc_lenlen( ber_len_t len ) static int ber_put_len( BerElement *ber, ber_len_t len, int nosos ) { - int i; + int rc; + int i,j; char lenlen; ber_len_t mask; - ber_len_t netlen; + unsigned char netlen[sizeof(ber_len_t)]; + ber_len_t xlen; assert( ber != NULL ); assert( BER_VALID( ber ) ); @@ -151,19 +158,24 @@ ber_put_len( BerElement *ber, ber_len_t len, int nosos ) lenlen = (unsigned char) ++i; if ( lenlen > 4 ) return( -1 ); + lenlen |= 0x80UL; /* write the length of the length */ if ( ber_write( ber, &lenlen, 1, nosos ) != 1 ) return( -1 ); + for( j=0; j>= 8; + } + /* write the length itself */ - netlen = LBER_LEN_HTON( len ); - if ( ber_write( ber, (char *) &netlen + (sizeof(ber_len_t) - i), i, nosos ) - != i ) - return( -1 ); + rc = ber_write( ber, + &netlen[sizeof(ber_len_t)-i], + i, nosos ); - return( i + 1 ); + return rc == i ? i+1 : -1; } static int @@ -172,9 +184,11 @@ ber_put_int_or_enum( ber_int_t num, ber_tag_t tag ) { - int i, sign; + int rc; + int i, j, sign; ber_len_t len, lenlen, taglen; - ber_uint_t unum, netnum, mask; + ber_uint_t unum, xnum, mask; + unsigned char netnum[sizeof(ber_uint_t)]; assert( ber != NULL ); assert( BER_VALID( ber ) ); @@ -216,13 +230,18 @@ ber_put_int_or_enum( if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 ) return( -1 ); i++; - netnum = LBER_INT_HTON( unum ); - if ( ber_write( ber, (char *) &netnum + (sizeof(ber_int_t) - i), i, 0 ) - != i ) - return( -1 ); + + for( j=0; j>= 8; + } + + rc = ber_write( ber, + &netnum[sizeof(ber_int_t) - i], + i, 0 ); /* length of tag + length + contents */ - return( taglen + lenlen + i ); + return rc == i ? taglen + lenlen + i : -1; } int @@ -484,7 +503,9 @@ ber_start_set( BerElement *ber, ber_tag_t tag ) static int ber_put_seqorset( BerElement *ber ) { - ber_len_t len, netlen; + int rc, i; + ber_len_t len; + unsigned char netlen[sizeof(ber_len_t)]; ber_len_t taglen, lenlen; unsigned char ltag = 0x80U + FOUR_BYTE_LEN - 1; Seqorset *next; @@ -502,16 +523,25 @@ ber_put_seqorset( BerElement *ber ) */ len = (*sos)->sos_clen; - netlen = LBER_LEN_HTON( len ); + if ( sizeof(ber_len_t) > 4 && len > 0xffffffffUL ) return( -1 ); if ( ber->ber_options & LBER_USE_DER ) { lenlen = ber_calc_lenlen( len ); + } else { lenlen = FOUR_BYTE_LEN; } + if( lenlen > 1 ) { + for( i=0; i < lenlen-1; i++ ) { + netlen[(sizeof(ber_len_t)-1) - i] = (len >> i*8) & 0xffU; + } + } else { + netlen[sizeof(ber_len_t)-1] = len & 0x7fU; + } + if ( (next = (*sos)->sos_next) == NULL ) { /* write the tag */ if ( (taglen = ber_put_tag( ber, (*sos)->sos_tag, 1 )) == -1 ) @@ -539,21 +569,33 @@ ber_put_seqorset( BerElement *ber ) return( -1 ); /* the length itself */ - if ( ber_write( ber, (char *) (&netlen + 1) - - (FOUR_BYTE_LEN - 1), FOUR_BYTE_LEN - 1, 1 ) - != FOUR_BYTE_LEN - 1 ) + rc = ber_write( ber, + &netlen[sizeof(ber_len_t) - (FOUR_BYTE_LEN-1)], + FOUR_BYTE_LEN-1, 1 ); + + if( rc != FOUR_BYTE_LEN - 1 ) { return( -1 ); + } } /* The ber_ptr is at the set/seq start - move it to the end */ (*sos)->sos_ber->ber_ptr += len; + } else { - ber_tag_t ntag; + int i; + unsigned char nettag[sizeof(ber_tag_t)]; + ber_tag_t tmptag = (*sos)->sos_tag; /* the tag */ - taglen = ber_calc_taglen( (*sos)->sos_tag ); - ntag = LBER_TAG_HTON( (*sos)->sos_tag ); - SAFEMEMCPY( (*sos)->sos_first, (char *) &ntag + - sizeof(ber_tag_t) - taglen, taglen ); + taglen = ber_calc_taglen( tmptag ); + + for( i = 0; i < taglen; i++ ) { + nettag[(sizeof(ber_tag_t)-1) - i] = tmptag & 0xffU; + tmptag >>= 8; + } + + SAFEMEMCPY( (*sos)->sos_first, + &nettag[sizeof(ber_tag_t) - taglen], + taglen ); if ( ber->ber_options & LBER_USE_DER ) { ltag = (lenlen == 1) @@ -568,9 +610,8 @@ ber_put_seqorset( BerElement *ber ) if (lenlen > 1) { /* Write the length itself */ SAFEMEMCPY( (*sos)->sos_first + 2, - (char *)&netlen + sizeof(ber_len_t) - - (lenlen - 1), - lenlen - 1 ); + &netlen[sizeof(ber_len_t) - (lenlen - 1)], + lenlen - 1 ); } if (lenlen != FOUR_BYTE_LEN) { /* @@ -585,8 +626,8 @@ ber_put_seqorset( BerElement *ber ) } else { /* the length itself */ SAFEMEMCPY( (*sos)->sos_first + taglen + 1, - (char *) &netlen + sizeof(ber_len_t) - - (FOUR_BYTE_LEN - 1), FOUR_BYTE_LEN - 1 ); + &netlen[sizeof(ber_len_t) - (FOUR_BYTE_LEN - 1)], + FOUR_BYTE_LEN - 1 ); } next->sos_clen += (taglen + lenlen + len); diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c index 57a2eceb4b..c5dc98f3a1 100644 --- a/libraries/liblber/io.c +++ b/libraries/liblber/io.c @@ -523,8 +523,9 @@ ber_get_next( ber->ber_tag = 0; } -#define PTR_IN_VAR( ptr, var )\ -(((ptr)>=(char *) &(var)) && ((ptr)< (char *) &(var)+sizeof(var))) +#undef PTR_IN_VAR +#define PTR_IN_VAR( ptr, var ) \ + (((ptr)>=(char *) &(var)) && ((ptr)< (char *) &(var)+sizeof(var))) if (PTR_IN_VAR(ber->ber_rwptr, ber->ber_tag)) { if (ber->ber_rwptr == (char *) &ber->ber_tag) { @@ -548,10 +549,11 @@ ber_get_next( ber->ber_rwptr = (char *) &ber->ber_usertag; goto get_lenbyte; } - } while (PTR_IN_VAR(ber->ber_rwptr,ber->ber_tag)); + } while( PTR_IN_VAR(ber->ber_rwptr, ber->ber_tag )); errno = ERANGE; /* this is a serious error. */ return LBER_DEFAULT; } + get_lenbyte: if (ber->ber_rwptr==(char *) &ber->ber_usertag) { unsigned char c; @@ -571,19 +573,28 @@ get_lenbyte: goto fill_buffer; } } + if (PTR_IN_VAR(ber->ber_rwptr, ber->ber_len)) { + unsigned char netlen[sizeof(ber_len_t)]; + ber_slen_t res; ber_slen_t to_go; to_go = (char *) &ber->ber_len + sizeof( ber->ber_len ) - ber->ber_rwptr; assert( to_go > 0 ); - res = ber_pvt_sb_read( sb, ber->ber_rwptr, to_go ); - if (res <=0) + res = ber_pvt_sb_read( sb, netlen, to_go ); + if (res <= 0) { return LBER_DEFAULT; + } ber->ber_rwptr += res; + if (res==to_go) { /* convert length. */ - ber->ber_len = LBER_LEN_NTOH( ber->ber_len ); + ber->ber_len = 0; + for( to_go = 0; to_go < res ; to_go++ ) { + ber->ber_len <<= 8; + ber->ber_len |= netlen[to_go]; + } goto fill_buffer; } else { #if defined( EWOULDBLOCK ) @@ -594,6 +605,7 @@ get_lenbyte: return LBER_DEFAULT; } } + fill_buffer: /* now fill the buffer. */ if (ber->ber_buf==NULL) { @@ -608,6 +620,7 @@ fill_buffer: ber->ber_ptr = ber->ber_buf; ber->ber_end = ber->ber_buf + ber->ber_len; } + if ((ber->ber_rwptr>=ber->ber_buf) && (ber->ber_rwptrber_end)) { ber_slen_t res; ber_slen_t to_go; diff --git a/libraries/liblber/lber-int.h b/libraries/liblber/lber-int.h index a643270e78..0904d886de 100644 --- a/libraries/liblber/lber-int.h +++ b/libraries/liblber/lber-int.h @@ -26,14 +26,6 @@ LDAP_BEGIN_DECL extern BER_ERRNO_FN ber_int_errno_fn; -/* these have to match lber types settings */ -#define LBER_INT_HTON(i) AC_HTONL(i) -#define LBER_INT_NTOH(i) AC_NTOHL(i) -#define LBER_LEN_HTON(l) AC_HTONL(l) -#define LBER_LEN_NTOH(l) AC_NTOHL(l) -#define LBER_TAG_HTON(t) AC_HTONL(t) -#define LBER_TAG_NTOH(t) AC_NTOHL(t) - struct lber_options { short lbo_valid; #define LBER_UNINITIALIZED 0x0