X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblber%2Fsockbuf.c;h=5bdce3efbca2e76492e0a71063463d3039c32523;hb=304a57740a0dbb8c95bbbdada7b7972eee521fa0;hp=52b32040814001e76cd979e07216df9b284768e3;hpb=7275861039abe6f1284923eea43aa5b6ec196d3f;p=openldap diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c index 52b3204081..5bdce3efbc 100644 --- a/libraries/liblber/sockbuf.c +++ b/libraries/liblber/sockbuf.c @@ -1,4 +1,5 @@ /* sockbuf.c - i/o routines with support for adding i/o layers. */ +/* $OpenLDAP$ */ /* * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file @@ -26,9 +27,6 @@ #include #endif -#undef LDAP_F_PRE -#define LDAP_F_PRE LDAP_F_EXPORT - #include "lber-int.h" #ifdef LDAP_TEST @@ -104,7 +102,7 @@ status_is_ok( Sockbuf *sb ) #ifdef USE_SASL static ber_len_t -packet_length( char *buf ) +packet_length( Sockbuf *sb, const char *buf ) { ber_len_t size; @@ -115,11 +113,11 @@ packet_length( char *buf ) (((ber_len_t)buf[2])<<8)| (((ber_len_t)buf[3])); - if ((size<0) || (size>MAX_BUF_SIZE)) { + if ( size > MAX_BUF_SIZE ) { /* somebody is trying to mess me up. */ - lber_log_printf( LDAP_DEBUG_SASL, sb->sb_debug, - "SASL: received packet length of %d bytes\n", - size ); + ber_log_printf( LDAP_DEBUG_SASL, sb->sb_debug, + "SASL: received packet length of %lu bytes\n", + (unsigned long) size ); size = 16; /* this should lead to an error. */ } @@ -228,7 +226,7 @@ sockbuf_sec_release( Sockbuf *sb, char *buf, ber_len_t len ) ptr+=size; if (ptr+4<=end) - size = packet_length( ptr ); + size = packet_length( sb, ptr ); /* size is always at least 4, so the loop condition is always OK !!*/ assert( size>=4 ); @@ -444,14 +442,14 @@ ber_pvt_sb_read( Sockbuf *sb, void *buf_arg, ber_len_t len ) } /* calculate the packet length. */ sb->sb_sec_buf_in.buf_end = - packet_length(sb->sb_sec_buf_in.buf_base ); + packet_length(sb, sb->sb_sec_buf_in.buf_base ); if ((sb->sb_sec_buf_in.buf_end > sb->sb_sec_buf_in.buf_size) && (grow_buffer( &(sb->sb_sec_buf_in), sb->sb_sec_buf_in.buf_end)<0)) { /* buffer has to be to big. exit with error. */ ret = -1; goto do_return; } - if (sb->sb_sec_buf_in.buf_ptr >= sb_sec_buf_in.buf_end) { + if (sb->sb_sec_buf_in.buf_ptr >= sb->sb_sec_buf_in.buf_end) { /* finished packet. decode it. */ goto decode_packet; } @@ -531,6 +529,7 @@ do_return: long sockbuf_do_write( Sockbuf *sb ) { long to_go; + ber_slen_t ret; assert( sb != NULL ); assert( SOCKBUF_VALID( sb ) ); @@ -782,10 +781,10 @@ int ber_pvt_sb_set_sec( Sockbuf *sb, Sockbuf_Sec * sec, void *arg ) memcpy( sb->sb_sec_buf_in.buf_base, sb->sb_buf.buf_base + sb->sb_buf.buf_ptr, len ); sb->sb_sec_buf_in.buf_ptr = len; - sb->sb_sec_buf_in.buf_end = (len>4) ? packet_length( sb->sb_sec_buf_in ) : 0; + sb->sb_sec_buf_in.buf_end = (len>4) ? packet_length( sb, sb->sb_sec_buf_in ) : 0; sb->sb_buf.buf_ptr = sb->sb_buf.buf_end = 0; } - update_status(); + update_status( sb ); return 0; } @@ -889,9 +888,17 @@ stream_read( Sockbuf *sb, void *buf, ber_len_t len ) { int rc; rc = recv( ber_pvt_sb_get_desc(sb), buf, len, 0 ); + #ifdef HAVE_WINSOCK - if ( rc < 0 ) errno = WSAGetLastError(); + if ( rc < 0 ) + { + int err; + + err = WSAGetLastError(); + errno = err; + } #endif + return rc; } #elif defined( HAVE_NCSA ) @@ -936,7 +943,12 @@ stream_write( Sockbuf *sb, void *buf, ber_len_t len ) int rc; rc = send( ber_pvt_sb_get_desc(sb), buf, len, 0 ); #ifdef HAVE_WINSOCK - if ( rc < 0 ) errno = WSAGetLastError(); + if ( rc < 0 ) + { + int err; + err = WSAGetLastError(); + errno = err; + } #endif return rc; } @@ -1026,8 +1038,8 @@ dgram_read( Sockbuf *sb, void *buf, ber_len_t len ) if ( sb->sb_debug ) { ber_log_printf( LDAP_DEBUG_ANY, sb->sb_debug, - "dgram_read udp_read %d bytes\n", - rc ); + "dgram_read udp_read %ld bytes\n", + (long) rc ); if ( rc > 0 ) ber_log_bprint( LDAP_DEBUG_PACKETS, sb->sb_debug, buf, rc );