From 4396ad33167596583ca748a022b33049482b73e5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 24 Oct 2002 11:39:06 +0000 Subject: [PATCH] ITS#2153, make sure sockbuf buffer is empty before returning (-2) from try_read1msg. Blind fix, problem was not duplicated/tested. --- libraries/libldap/ldap-int.h | 3 +++ libraries/libldap/result.c | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index b0c2bd9361..dfb68d643f 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -311,6 +311,9 @@ struct ldap { LDAPConn *ld_defconn; /* default connection */ LDAPConn *ld_conns; /* list of server connections */ void *ld_selectinfo; /* platform specifics for select */ +#ifdef HAVE_TLS + void *ld_ssl; /* SSL session for next connection */ +#endif }; #define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION ) diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 7ea3a474f4..574ff9449a 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -416,6 +416,7 @@ try_read1msg( Debug( LDAP_DEBUG_TRACE, "read1msg: msgid %d, all %d\n", msgid, all, 0 ); #endif +retry: if ( lc->lconn_ber == NULL ) { lc->lconn_ber = ldap_alloc_ber_with_options(ld); @@ -427,6 +428,7 @@ try_read1msg( ber = lc->lconn_ber; assert( LBER_VALID (ber) ); +retry2: /* get the next message */ errno = 0; #ifdef LDAP_CONNECTIONLESS @@ -475,12 +477,17 @@ try_read1msg( /* if it's been abandoned, toss it */ if ( ldap_abandoned( ld, id ) ) { - ber_free( ber, 1 ); #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, DETAIL1, "read1msg: abandoned\n", 0, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0); #endif +retry_ber: + if ( ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ) ) { + ber_init2( ber, NULL, ld->ld_lberoptions ); + goto retry2; + } + ber_free( ber, 1 ); return( -2 ); /* continue looking */ } @@ -494,8 +501,7 @@ try_read1msg( "no request for response with msgid %ld (tossing)\n", (long) id, 0, 0 ); #endif - ber_free( ber, 1 ); - return( -2 ); /* continue looking */ + goto retry_ber; } #ifdef LDAP_CONNECTIONLESS if (LDAP_IS_UDP(ld) && ld->ld_options.ldo_version == LDAP_VERSION2) { @@ -843,7 +849,7 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); new->lm_next = ld->ld_responses; ld->ld_responses = new; - return( -2 ); /* continue looking */ + goto leave; } #ifdef NEW_LOGGING @@ -886,6 +892,10 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); #endif /* !LDAP_WORLD_P16 */ } +leave: + if ( ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ) ) { + goto retry; + } return( -2 ); /* continue looking */ } -- 2.39.5