From 0ccbce9d097e5fd9a5cc6f3dcf9c08dfca50ab90 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Thu, 2 Mar 2006 16:50:34 +0000 Subject: [PATCH] Always pass valid BerElement to ldap_create_control() to avoid assert fail --- libraries/libldap/pagectrl.c | 9 ++++++++- libraries/libldap/sortctrl.c | 9 ++++++++- libraries/libldap/vlvctrl.c | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libraries/libldap/pagectrl.c b/libraries/libldap/pagectrl.c index f5ca3a54ee..40093cb6fd 100644 --- a/libraries/libldap/pagectrl.c +++ b/libraries/libldap/pagectrl.c @@ -141,6 +141,7 @@ ldap_create_page_control( LDAPControl **ctrlp ) { struct berval value; + BerElement *ber; if ( ctrlp == NULL ) { ld->ld_errno = LDAP_PARAM_ERROR; @@ -150,13 +151,19 @@ ldap_create_page_control( ld->ld_errno = ldap_create_page_control_value( ld, pagesize, cookie, &value ); if ( ld->ld_errno == LDAP_SUCCESS ) { + if ((ber = ldap_alloc_ber_with_options(ld)) == NULL) { + ld->ld_errno = LDAP_NO_MEMORY; + return LDAP_NO_MEMORY; + } + ld->ld_errno = ldap_create_control( LDAP_CONTROL_PAGEDRESULTS, - NULL, iscritical, ctrlp ); + ber, iscritical, ctrlp ); if ( ld->ld_errno == LDAP_SUCCESS ) { (*ctrlp)->ldctl_value = value; } else { LDAP_FREE( value.bv_val ); } + ber_free(ber, 1); } return ld->ld_errno; diff --git a/libraries/libldap/sortctrl.c b/libraries/libldap/sortctrl.c index f4c881af7b..3875387e21 100644 --- a/libraries/libldap/sortctrl.c +++ b/libraries/libldap/sortctrl.c @@ -409,6 +409,7 @@ ldap_create_sort_control( LDAPControl **ctrlp ) { struct berval value; + BerElement *ber; if ( ctrlp == NULL ) { ld->ld_errno = LDAP_PARAM_ERROR; @@ -417,13 +418,19 @@ ldap_create_sort_control( ld->ld_errno = ldap_create_sort_control_value( ld, keyList, &value ); if ( ld->ld_errno == LDAP_SUCCESS ) { + if ((ber = ldap_alloc_ber_with_options(ld)) == NULL) { + ld->ld_errno = LDAP_NO_MEMORY; + return LDAP_NO_MEMORY; + } + ld->ld_errno = ldap_create_control( LDAP_CONTROL_SORTREQUEST, - NULL, isCritical, ctrlp ); + ber, isCritical, ctrlp ); if ( ld->ld_errno == LDAP_SUCCESS ) { (*ctrlp)->ldctl_value = value; } else { LDAP_FREE( value.bv_val ); } + ber_free(ber, 1); } return ld->ld_errno; diff --git a/libraries/libldap/vlvctrl.c b/libraries/libldap/vlvctrl.c index 6f4feeb805..ab731007cd 100644 --- a/libraries/libldap/vlvctrl.c +++ b/libraries/libldap/vlvctrl.c @@ -212,6 +212,7 @@ ldap_create_vlv_control( LDAPControl **ctrlp ) { struct berval value; + BerElement *ber; if ( ctrlp == NULL ) { ld->ld_errno = LDAP_PARAM_ERROR; @@ -220,13 +221,19 @@ ldap_create_vlv_control( ld->ld_errno = ldap_create_vlv_control_value( ld, vlvinfop, &value ); if ( ld->ld_errno == LDAP_SUCCESS ) { + if ((ber = ldap_alloc_ber_with_options(ld)) == NULL) { + ld->ld_errno = LDAP_NO_MEMORY; + return LDAP_NO_MEMORY; + } + ld->ld_errno = ldap_create_control( LDAP_CONTROL_VLVREQUEST, - NULL, 1, ctrlp ); + ber, 1, ctrlp ); if ( ld->ld_errno == LDAP_SUCCESS ) { (*ctrlp)->ldctl_value = value; } else { LDAP_FREE( value.bv_val ); } + ber_free(ber, 1); } return ld->ld_errno; -- 2.39.5