]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9996 librewrite plug potential leak in ldapmap map_ldap_apply()
authorHoward Chu <hyc@openldap.org>
Thu, 2 Feb 2023 15:08:34 +0000 (15:08 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 26 Apr 2023 16:43:40 +0000 (16:43 +0000)
libraries/librewrite/ldapmap.c

index 7d0252bb320186ac974736bc83293bb2b9d7e631..d9437d1a4b9b26f5fdc804ae5609e3ef08792ffc 100644 (file)
@@ -360,11 +360,13 @@ do_bind:;
                        data->lm_attrs, 0, NULL, NULL, NULL, 1, &res );
        if ( rc == LDAP_SERVER_DOWN && first_try ) {
                first_try = 0;
-                if ( ldap_initialize( &ld, data->lm_url ) != LDAP_SUCCESS ) {
+               if ( ldap_initialize( &ld, data->lm_url ) != LDAP_SUCCESS ) {
                        rc = REWRITE_ERR;
                        goto rc_return;
                }
                set_version = 1;
+               ldap_msgfree( res );
+               res = NULL;
                goto do_bind;
 
        } else if ( rc != LDAP_SUCCESS ) {
@@ -373,7 +375,6 @@ do_bind:;
        }
 
        if ( ldap_count_entries( ld, res ) != 1 ) {
-               ldap_msgfree( res );
                rc = REWRITE_ERR;
                goto rc_return;
        }
@@ -408,14 +409,14 @@ do_bind:;
                }
        }
        
-       ldap_msgfree( res );
-
        if ( val->bv_val == NULL ) {
                rc = REWRITE_ERR;
                goto rc_return;
        }
 
 rc_return:;
+       ldap_msgfree( res );
+
        if ( data->lm_when == MAP_LDAP_EVERYTIME ) {
                if ( ld != NULL ) {
                        ldap_unbind_ext( ld, NULL, NULL );