Bug 17583 - ldap_str2dn funktioniert auf amd64-Systemen nicht
ldap_str2dn funktioniert auf amd64-Systemen nicht
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: LDAP
UCS 2.3
Other Linux
: P5 normal (vote)
: UCS 2.3-2
Assigned To: Arvid Requate
Felix Botner
:
: 16655 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-08 11:16 CET by Andreas Büsching
Modified: 2010-05-18 10:00 CEST (History)
5 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments
Fix für den AD Connector auf amd64-Systemen (790 bytes, patch)
2010-02-08 11:16 CET, Andreas Büsching
Details | Diff
str2dn aus python-ldap ist unter python2.4 auf amd64 instabil (337 bytes, application/x-python)
2010-03-10 22:19 CET, Arvid Requate
Details
ohne thread locking (315 bytes, application/x-python)
2010-03-10 22:21 CET, Arvid Requate
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Büsching univentionstaff 2010-02-08 11:16:21 CET
Created attachment 2280 [details]
Fix für den AD Connector auf amd64-Systemen

Aufgefallen ist dies beim AD Connector. Dort wird bei der Synchronisation in
das UCS LDAP-Verzeichnis folgender Traceback dadurch erzeugt:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/univention/connector/ad/__init__.py",
line 1644, in poll
    sync_successfull = self.sync_to_ucs(property_key, mapped_object,
object['dn'])
  File "/usr/lib/python2.4/site-packages/univention/connector/__init__.py",
line 985, in sync_to_ucs
    'sync_to_ucs: set position to %s' % string.join( ldap.explode_dn(
object['dn'] )[1:], "," ) )
  File "/usr/lib/python2.4/site-packages/ldap/dn.py", line 79, in explode_dn
    dn_decomp = str2dn(dn,flags)
  File "/usr/lib/python2.4/site-packages/ldap/dn.py", line 53, in str2dn
    return ldap.functions._ldap_function_call(_ldap.str2dn,dn,flags)
  File "/usr/lib/python2.4/site-packages/ldap/functions.py", line 58, in
_ldap_function_call
    result = func(*args,**kwargs)
DECODING_ERROR

Der gleiche Fehler kann in einer interaktiven Python-Shell hervorgerufen
werden:

root@ma30:~# python2.4
Python 2.4.6 (#2, Oct  4 2009, 01:19:18) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldap
>>> ldap.str2dn( 'c=b,d=k' )
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ldap.DECODING_ERROR

Der angehängte Patch behebt das Problem für den AD Connector. Der Patch ist
aber nur ein Workaround.
Comment 1 Stefan Gohmann univentionstaff 2010-02-08 19:26:20 CET
Tritt das Problem auf 2.3-1 Systemen auch noch auf?
Comment 2 Andreas Büsching univentionstaff 2010-02-09 11:01:10 CET
(In reply to comment #1)
> Tritt das Problem auf 2.3-1 Systemen auch noch auf?

ja
Comment 3 Stefan Gohmann univentionstaff 2010-02-09 16:23:44 CET
*** Bug 16655 has been marked as a duplicate of this bug. ***
Comment 4 Arvid Requate univentionstaff 2010-03-10 22:19:50 CET
Created attachment 2332 [details]
str2dn aus python-ldap ist unter python2.4 auf amd64 instabil

Wenn man die beiden auskommentierten dummy print Anweisungen in den Zeilen 11 und 12 des Scripts wieder einkommentiert, tritt der ldap.DECODING_ERROR aus Zeile 4 unter amd64 nicht mehr auf. Bogous.

Auch interaktiv testbar:

arequate@norrebo:~$ python2.4
Python 2.4.6 (#2, Oct  4 2009, 01:19:18)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldap; print ldap.str2dn('c=de')
[[('c', 'de', 1)]]   <-GEHT

>>> print ldap.str2dn('c=de')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ldap.DECODING_ERROR

Unter python2.5 scheint es hingegen stabil zu sein.
Comment 5 Arvid Requate univentionstaff 2010-03-10 22:21:09 CET
Created attachment 2333 [details]
ohne thread locking

Was auch mit python2.4 meist stabil zu funktionieren scheint ist, die Funktion ohne Verwendung von _ldap_function_call direkt aufzurufen:
>>> import _ldap
>>> _ldap.str2dn('c=de')
[[('c', 'de', 1)]]
>>> _ldap.str2dn(u'CN=Dom\xe4ne')
[[('CN', 'Dom\xc3\xa4ne', 4)]]

Aber auch das nicht immer, siehe angehängtes Script.
Comment 6 Arvid Requate univentionstaff 2010-03-11 17:12:55 CET
Es scheint sich um in Problem zwischen PyArg_ParseTuple, size_t und ber_len_t zu handeln (letzeres ist unsigned LBER_LEN_T, d.h. unsigned long laut lber_types.h), über dass dann ein memchr-Aufruf in libldap_r-2.4 stolpert.

Im Python-Binding l_ldap_str2dn für ldap_bv2dn wird die Länge des übergebenen Python-Strings per PyArg_ParseTuple in ein bervalue.bv_len geschrieben. Damit scheint unter amd64 und python2.4 irgendwas nicht korrekt zu sein, denn der memchr-Aufruf in der OpenLDAP Funktion ldap_bv2dn interpretiert diese Zahl als einen viel zu großen Wert und stolpert dann bei Character bv_len+1 über das (korrekte) Nullbyte, das am Ende des Strings gesetzt ist (openldap-2.4.15). Bizarr ist, dass das nur unter ganz bestimmten Umständen auftritt: Wenn man Andreas' Beispiel oben in einer Zeile eingibt (interaktiv in python2.4), d.h.

>>> import ldap; ldap.str2dn('c=b,d=k')

funktioniert der memchr-Aufruf und alles geht gut. (Ich würde es auch nicht glauben, wenn mir das jemand erzählt..). Ebenso, wenn man ihn in einer Datei als Script ausführen lässt.

Als Workaround funktionierte in Tests, in dem Python-Binding l_ldap_str2dn die Länge des Strings (bv_len) explizit in eine unsigned int zu casten, vor dem Aufruf von ldap_bv2dn. Der Patch python-ldap/2.3-0-0-ucs/2.3.5-1-ucs2.3-2/10_str2dn.patch macht das jetzt, falls die Architektur __x86_64__ ist.
Comment 7 Arvid Requate univentionstaff 2010-03-11 17:28:01 CET
Auch die in der API-Doku empfohlene Variante

ldap.dn.str2dn('c=de', flags=ldap.DN_FORMAT_LDAPV3)

geht ohne den Patch nicht immer (http://www.python-ldap.org/doc/html/ldap-dn.html):

>>> ldap.dn.str2dn('c=de', flags=ldap.DN_FORMAT_LDAPV3)
[[('c', 'de', 1)]]
>>> print ldap.dn.str2dn('c=de', flags=ldap.DN_FORMAT_LDAPV3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/ldap/dn.py", line 53, in str2dn
    return ldap.functions._ldap_function_call(_ldap.str2dn,dn,flags)
  File "/usr/lib/python2.4/site-packages/ldap/functions.py", line 58, in _ldap_function_call
    result = func(*args,**kwargs)
ldap.DECODING_ERROR

Mit dem Patch geht es hingegen.
Comment 8 Arvid Requate univentionstaff 2010-03-12 17:42:20 CET
Antwort von der Mailingliste, der upstream-Patch ist ziemlich genau wie unserer. Um sicher zu gehen, wenden wir jetzt den upstream-Patch an. Paket ist neu gebaut.
-------
I think it is fixed since release 2.3.7. You should encourage the Debian
maintainer to provide an updated package.

See CVS:

http://python-ldap.cvs.sourceforge.net/viewvc/python-ldap/python-ldap/Modules/functions.c?r1=1.21&r2=1.22

Revision 1.22
Tue Apr 7 16:45:57 2009 UTC (11 months ago) by stroeder
Branch: MAIN
CVS Tags: PYLDAP_REL_2_3_7

Fixed functions.c not to raise ldap.ENCODING_ERROR in function l_ldap_str2dn()
on 64-bit systems (see SF#2725356)

Ciao, Michael.
-------
Comment 9 Felix Botner univentionstaff 2010-04-20 16:48:27 CEST
OK, folgende Aufrufe funktionieren mit python2.4 unter i386 und amd64:

>>> import ldap

>>> ldap.dn.str2dn('c=de', flags=ldap.DN_FORMAT_LDAPV3)
[[('c', 'de', 1)]]

>>> print ldap.dn.str2dn('c=de', flags=ldap.DN_FORMAT_LDAPV3)
[[('c', 'de', 1)]]

>>> ldap.str2dn(u'CN=Dom\xe4ne')
[[('CN', 'Dom\xc3\xa4ne', 4)]]

>>> print ldap.str2dn(u'CN=Dom\xe4ne')
[[('CN', 'Dom\xc3\xa4ne', 4)]]

>>> print ldap.dn.str2dn(u'CN=Dom\xe4ne',flags=ldap.DN_FORMAT_LDAPV3)
[[('CN', 'Dom\xc3\xa4ne', 4)]]

>>> ldap.dn.str2dn(u'CN=Dom\xe4ne',flags=ldap.DN_FORMAT_LDAPV3)
[[('CN', 'Dom\xc3\xa4ne', 4)]]

>>> print ldap.str2dn('c=de')
[[('c', 'de', 1)]]

>>> ldap.str2dn('c=de')
[[('c', 'de', 1)]]

Changelog Eintrag nicht vorhanden.
Comment 10 Arvid Requate univentionstaff 2010-04-20 17:44:58 CEST
Changelog ist jetzt aktualisiert.
Comment 11 Felix Botner univentionstaff 2010-04-22 16:59:15 CEST
changelog Eintrag vorhanden
Comment 12 Stefan Gohmann univentionstaff 2010-05-18 10:00:05 CEST
UCS 2.3-2 wurde veröffentlicht. Sollte der hier beschriebene Bug mit einer neueren Version von UCS erneut auftreten, so sollte der Bug dupliziert werden:
"Clone This Bug".