[python-ldap] Reraising wrong exception in _ldap_call()

Aigars Grins aigars.grins at sentor.se
Tue Sep 26 03:00:08 EDT 2017


In ldap.ldapobject theres a method called SimpleLDAPObject._ldap_call(). 
In it there's error handling code along the lines of (abbreviated here):

     result = func(*args, **kwargs)
except LDAPError, e:
         if not e.args[0].has_key('info') and e.args[0].has_key('errno'):
             e.args[0]['info'] = strerror(e.args[0]['errno'])
     except IndexError:

This means that if the raised LDAPError was e.g. a TIMEOUT w/o any args, 
then the `e.args[0]` will raise an IndexError. That will be caught, 
which is fine. But then the reraise will reraise not the LDAPError but 
the IndexError.

So the `raise` should be replaced with `raise e`.

The way I found this was by running something along the lines of:

msgid = cnxn.search_ext(base, scope, ..., timeout = 0.00001)
cnxn.result(msgid, timeout = 0.00001)

The short timeouts triggers a TIMEOUT, but it doesn't have any args.

Aigars Grins

More information about the python-ldap mailing list