mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-03-07 14:18:15 +08:00
Timeouts should not be malloc'd
This commit is contained in:
parent
4e193bc5cb
commit
0c542682b1
@ -259,7 +259,6 @@ static void openldap_ldap_init_w_conf(
|
||||
case ATTR_OPT_TV: {
|
||||
struct timeval tv;
|
||||
char *next;
|
||||
tv.tv_sec = -1;
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = strtol( opt, &next, 10 );
|
||||
if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
|
||||
@ -476,8 +475,8 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl
|
||||
gopts->ldo_timelimit = LDAP_NO_LIMIT;
|
||||
gopts->ldo_sizelimit = LDAP_NO_LIMIT;
|
||||
|
||||
gopts->ldo_tm_api = (struct timeval *)NULL;
|
||||
gopts->ldo_tm_net = (struct timeval *)NULL;
|
||||
gopts->ldo_tm_api.tv_sec = -1;
|
||||
gopts->ldo_tm_net.tv_sec = -1;
|
||||
|
||||
/* ldo_defludp will be freed by the termination handler
|
||||
*/
|
||||
|
@ -173,8 +173,8 @@ struct ldapoptions {
|
||||
#endif
|
||||
|
||||
/* per API call timeout */
|
||||
struct timeval *ldo_tm_api;
|
||||
struct timeval *ldo_tm_net;
|
||||
struct timeval ldo_tm_api;
|
||||
struct timeval ldo_tm_net;
|
||||
|
||||
ber_int_t ldo_version;
|
||||
ber_int_t ldo_deref;
|
||||
|
@ -122,8 +122,6 @@ ldap_create( LDAP **ldp )
|
||||
/* but not pointers to malloc'ed items */
|
||||
ld->ld_options.ldo_sctrls = NULL;
|
||||
ld->ld_options.ldo_cctrls = NULL;
|
||||
ld->ld_options.ldo_tm_api = NULL;
|
||||
ld->ld_options.ldo_tm_net = NULL;
|
||||
ld->ld_options.ldo_defludp = NULL;
|
||||
|
||||
#ifdef HAVE_CYRUS_SASL
|
||||
@ -146,14 +144,6 @@ ldap_create( LDAP **ldp )
|
||||
ld->ld_options.ldo_tls_ctx = NULL;
|
||||
#endif
|
||||
|
||||
if ( gopts->ldo_tm_api &&
|
||||
ldap_int_timeval_dup( &ld->ld_options.ldo_tm_api, gopts->ldo_tm_api ))
|
||||
goto nomem;
|
||||
|
||||
if ( gopts->ldo_tm_net &&
|
||||
ldap_int_timeval_dup( &ld->ld_options.ldo_tm_net, gopts->ldo_tm_net ))
|
||||
goto nomem;
|
||||
|
||||
if ( gopts->ldo_defludp ) {
|
||||
ld->ld_options.ldo_defludp = ldap_url_duplist(gopts->ldo_defludp);
|
||||
|
||||
@ -178,8 +168,6 @@ ldap_create( LDAP **ldp )
|
||||
nomem:
|
||||
ldap_free_select_info( ld->ld_selectinfo );
|
||||
ldap_free_urllist( ld->ld_options.ldo_defludp );
|
||||
LDAP_FREE( ld->ld_options.ldo_tm_net );
|
||||
LDAP_FREE( ld->ld_options.ldo_tm_api );
|
||||
#ifdef HAVE_CYRUS_SASL
|
||||
LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
|
||||
LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
|
||||
|
@ -176,17 +176,11 @@ ldap_get_option(
|
||||
return LDAP_OPT_SUCCESS;
|
||||
|
||||
case LDAP_OPT_TIMEOUT:
|
||||
/* the caller has to free outvalue ! */
|
||||
if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api ) != 0 ) {
|
||||
return LDAP_OPT_ERROR;
|
||||
}
|
||||
*(struct timeval *) outvalue = lo->ldo_tm_api;
|
||||
return LDAP_OPT_SUCCESS;
|
||||
|
||||
case LDAP_OPT_NETWORK_TIMEOUT:
|
||||
/* the caller has to free outvalue ! */
|
||||
if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) {
|
||||
return LDAP_OPT_ERROR;
|
||||
}
|
||||
*(struct timeval *) outvalue = lo->ldo_tm_net;
|
||||
return LDAP_OPT_SUCCESS;
|
||||
|
||||
case LDAP_OPT_DEREF:
|
||||
@ -452,28 +446,14 @@ ldap_set_option(
|
||||
const struct timeval *tv =
|
||||
(const struct timeval *) invalue;
|
||||
|
||||
if ( lo->ldo_tm_api != NULL ) {
|
||||
LDAP_FREE( lo->ldo_tm_api );
|
||||
lo->ldo_tm_api = NULL;
|
||||
}
|
||||
|
||||
if ( ldap_int_timeval_dup( &lo->ldo_tm_api, tv ) != 0 ) {
|
||||
return LDAP_OPT_ERROR;
|
||||
}
|
||||
lo->ldo_tm_api = *tv;
|
||||
} return LDAP_OPT_SUCCESS;
|
||||
|
||||
case LDAP_OPT_NETWORK_TIMEOUT: {
|
||||
const struct timeval *tv =
|
||||
(const struct timeval *) invalue;
|
||||
|
||||
if ( lo->ldo_tm_net != NULL ) {
|
||||
LDAP_FREE( lo->ldo_tm_net );
|
||||
lo->ldo_tm_net = NULL;
|
||||
}
|
||||
|
||||
if ( ldap_int_timeval_dup( &lo->ldo_tm_net, tv ) != 0 ) {
|
||||
return LDAP_OPT_ERROR;
|
||||
}
|
||||
lo->ldo_tm_net = *tv;
|
||||
} return LDAP_OPT_SUCCESS;
|
||||
|
||||
case LDAP_OPT_HOST_NAME: {
|
||||
|
@ -354,8 +354,7 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s,
|
||||
int async)
|
||||
{
|
||||
int rc, err;
|
||||
struct timeval tv = { 0 },
|
||||
*opt_tv = NULL;
|
||||
struct timeval tv, *opt_tv = NULL;
|
||||
|
||||
#ifdef LDAP_CONNECTIONLESS
|
||||
/* We could do a connect() but that would interfere with
|
||||
@ -369,9 +368,9 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s,
|
||||
return ( 0 );
|
||||
}
|
||||
#endif
|
||||
opt_tv = ld->ld_options.ldo_tm_net;
|
||||
if ( opt_tv != NULL ) {
|
||||
tv = *opt_tv;
|
||||
if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
|
||||
tv = ld->ld_options.ldo_tm_net;
|
||||
opt_tv = &tv;
|
||||
}
|
||||
|
||||
osip_debug(ld, "ldap_pvt_connect: fd: %d tm: %ld async: %d\n",
|
||||
|
@ -168,12 +168,11 @@ static int
|
||||
ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async)
|
||||
{
|
||||
int rc;
|
||||
struct timeval tv = { 0 },
|
||||
*opt_tv = NULL;
|
||||
struct timeval tv, *opt_tv = NULL;
|
||||
|
||||
opt_tv = ld->ld_options.ldo_tm_net;
|
||||
if ( opt_tv != NULL ) {
|
||||
tv = *opt_tv;
|
||||
if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
|
||||
tv = ld->ld_options.ldo_tm_net;
|
||||
opt_tv = &tv;
|
||||
}
|
||||
|
||||
oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n",
|
||||
|
@ -223,18 +223,16 @@ ldap_send_server_request(
|
||||
lc->lconn_status = LDAP_CONNST_CONNECTED;
|
||||
break;
|
||||
|
||||
case -2: {
|
||||
case -2:
|
||||
/* async only occurs if a network timeout is set */
|
||||
struct timeval *tvp = ld->ld_options.ldo_tm_net;
|
||||
assert( tvp != NULL );
|
||||
|
||||
/* honor network timeout */
|
||||
if ( time( NULL ) - lc->lconn_created <= tvp->tv_sec )
|
||||
{
|
||||
/* caller will have to call again */
|
||||
ld->ld_errno = LDAP_X_CONNECTING;
|
||||
}
|
||||
} /* fallthru */
|
||||
/* honor network timeout */
|
||||
if ( time( NULL ) - lc->lconn_created <= ld->ld_options.ldo_tm_net.tv_sec )
|
||||
{
|
||||
/* caller will have to call again */
|
||||
ld->ld_errno = LDAP_X_CONNECTING;
|
||||
}
|
||||
/* fallthru */
|
||||
|
||||
default:
|
||||
/* error */
|
||||
|
@ -275,8 +275,9 @@ wait4msg(
|
||||
LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex );
|
||||
#endif
|
||||
|
||||
if ( timeout == NULL ) {
|
||||
timeout = ld->ld_options.ldo_tm_api;
|
||||
if ( timeout == NULL && ld->ld_options.ldo_tm_api.tv_sec >= 0 ) {
|
||||
tv = ld->ld_options.ldo_tm_api;
|
||||
timeout = &tv;
|
||||
}
|
||||
|
||||
#ifdef LDAP_DEBUG
|
||||
|
@ -144,16 +144,6 @@ ldap_ld_free(
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( ld->ld_options.ldo_tm_api != NULL ) {
|
||||
LDAP_FREE( ld->ld_options.ldo_tm_api );
|
||||
ld->ld_options.ldo_tm_api = NULL;
|
||||
}
|
||||
|
||||
if ( ld->ld_options.ldo_tm_net != NULL ) {
|
||||
LDAP_FREE( ld->ld_options.ldo_tm_net );
|
||||
ld->ld_options.ldo_tm_net = NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CYRUS_SASL
|
||||
if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
|
||||
LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
|
||||
|
Loading…
Reference in New Issue
Block a user