cannatag / ldap3

a strictly RFC 4510 conforming LDAP V3 pure Python client. The same codebase works with Python 2. Python 3, PyPy and PyPy3
Other
870 stars 267 forks source link

RecursionError: maximum recursion depth exceeded ( #1128

Open jwalstra-keeper opened 5 months ago

jwalstra-keeper commented 5 months ago

I'm performing a search for a user.

            self.connection.search(dn,
                                   search_filter='(objectClass=*)',
                                   search_scope=BASE,
                                   attributes=['*'])

I'm getting the following error.

  File "ldap3\strategy\sync.py", line 178, in post_send_search
  File "ldap3\strategy\base.py", line 383, in get_response
  File "ldap3\strategy\base.py", line 810, in do_operation_on_referral
  File "ldap3\core\connection.py", line 853, in search
  File "ldap3\strategy\sync.py", line 178, in post_send_search
  File "ldap3\strategy\base.py", line 383, in get_response
  ...
  File "ldap3\core\connection.py", line 853, in search
  File "ldap3\strategy\base.py", line 331, in send
  File "ldap3\strategy\base.py", line 870, in sending
  File "pyasn1\codec\ber\encoder.py", line 862, in __call__
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 102, in encode
  File "pyasn1\codec\ber\encoder.py", line 589, in encodeValue
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 86, in encode
  File "pyasn1\codec\ber\encoder.py", line 697, in encodeValue
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 102, in encode
  File "pyasn1\codec\ber\encoder.py", line 589, in encodeValue
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 86, in encode
  File "pyasn1\codec\ber\encoder.py", line 697, in encodeValue
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 102, in encode
  File "pyasn1\codec\ber\encoder.py", line 589, in encodeValue
  File "pyasn1\codec\ber\encoder.py", line 843, in __call__
  File "pyasn1\codec\ber\encoder.py", line 102, in encode
  File "pyasn1\codec\ber\encoder.py", line 234, in encodeValue
RecursionError: maximum recursion depth exceeded

I know I could make a better filter by using person instead of a wild star. Could this be due to the configuration of the Active Directory server? I'm a programmer, not an AD admin. I also do not have access to the Active Directory.

Any help would most appreciated, John

cannatag commented 5 months ago

Hi, this is not related to ldap3 but to the response received from the server. Were you able to fix it?

BrysonMcI commented 4 months ago

I've seen this bug as well recently, it seems to happen when there is a cycle in referrals or for some reason a server refers to itself.

It seems like https://github.com/cannatag/ldap3/blob/86a9e7afedba7f7ca9eeb43710054abaf654539b/ldap3/strategy/base.py#L692 is supposed to protect against this recursion depth, but _referrals is never modified from what I can find, so it never uses this condition.

The more annoying part that I've run into is that the connections are not properly cleaned up when this happens, causing new sockets to be made and left open once the recursion depth is hit, eventually running my process out of file descriptors.