]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/sasl.c
Fix off by one bug
[openldap] / libraries / libldap / sasl.c
index a98f41e205d23f2dc5ca8d137760947c061c18ef..e22b11ce96fa47f9859a9e20705a0b37471f5a5e 100644 (file)
@@ -103,7 +103,7 @@ ldap_sasl_bind(
                        ld->ld_version, dn, LDAP_AUTH_SIMPLE,
                        cred );
                
-       } else if ( cred == NULL ) {
+       } else if ( cred == NULL || !cred->bv_len ) {
                /* SASL bind w/o creditials */
                rc = ber_printf( ber, "{it{ist{sN}N}" /*}*/,
                        ++ld->ld_msgid, LDAP_REQ_BIND,
@@ -357,7 +357,7 @@ ldap_pvt_sasl_getmechs ( LDAP *ld, char **pmechlist )
 
        Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_getmech\n", 0, 0, 0 );
 
-       rc = ldap_search_s( ld, NULL, LDAP_SCOPE_BASE,
+       rc = ldap_search_s( ld, "", LDAP_SCOPE_BASE,
                NULL, attrs, 0, &res );
 
        if ( rc != LDAP_SUCCESS ) {
@@ -366,24 +366,25 @@ ldap_pvt_sasl_getmechs ( LDAP *ld, char **pmechlist )
                
        e = ldap_first_entry( ld, res );
        if ( e == NULL ) {
+               ldap_msgfree( res );
                if ( ld->ld_errno == LDAP_SUCCESS ) {
-                       ld->ld_errno = LDAP_UNAVAILABLE;
+                       ld->ld_errno = LDAP_NO_SUCH_OBJECT;
                }
                return ld->ld_errno;
        }
 
        values = ldap_get_values( ld, e, "supportedSASLMechanisms" );
        if ( values == NULL ) {
-               ld->ld_errno = LDAP_NO_SUCH_ATTRIBUTE;
                ldap_msgfree( res );
+               ld->ld_errno = LDAP_NO_SUCH_ATTRIBUTE;
                return ld->ld_errno;
        }
 
        mechlist = ldap_charray2str( values, " " );
        if ( mechlist == NULL ) {
-               ld->ld_errno = LDAP_NO_MEMORY;
                LDAP_VFREE( values );
                ldap_msgfree( res );
+               ld->ld_errno = LDAP_NO_MEMORY;
                return ld->ld_errno;
        }