Hello,
we had a problem with ldap.dn.str2dn showing instable behavior and throwing
ldap.DECODING_ERROR in python2.4 Debian Lenny (amd64).
It seems that using PyArg_ParseTuple with format string "z#" and saving the
length of the string directly into the berval member bv_len does not store a
correct value, which in turn causes the problem in ldap_bv2dn. It seems that
str2dn is the only location in python-ldap (2.3.5) where this technique is
used, and the problems seems to affect only amd64 and might be caused by a
leak in the PyArg_ParseTuple routine of python2.4.
The attached patch solved the problem for us.
Cheers,
Arvid
--
Arvid Requate
Open Source Software Engineer
Univention GmbH
Linux for your business
Mary-Somerville-Str.1
28359 Bremen
Tel. : +49 421 22232-0
Fax : +49 421 22232-99
requ...@univention.de
http://www.univention.de
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876
diff -U 4 -Narp python-ldap-2.3.5.orig/Modules/functions.c python-ldap-2.3.5/Modules/functions.c
--- python-ldap-2.3.5.orig/Modules/functions.c 2008-03-20 13:24:56.000000000 +0100
+++ python-ldap-2.3.5/Modules/functions.c 2010-03-12 11:27:14.000000000 +0100
@@ -37,19 +37,33 @@ l_ldap_str2dn( PyObject* unused, PyObjec
LDAPDN dn;
int flags = 0;
PyObject *result = NULL, *tmp;
int res, i, j;
+ ber_len_t str_len;
/*
* From a DN string such as "a=b,c=d;e=f", build
* a list-equivalent of AVA structures; namely:
* ((('a','b',1),('c','d',1)),(('e','f',1),))
* The integers are a bit combination of the AVA_* flags
*/
if (!PyArg_ParseTuple( args, "z#|i:str2dn",
- &str.bv_val, &str.bv_len, &flags ))
+ &str.bv_val, &str_len, &flags ))
return NULL;
+ /* workaround for amd64 problem with PyArg_ParseTuple "z#" in python2.4:
+ * if PyArg_ParseTuple writes into &str.bv_len directly,
+ * which is passed as third (num) parameter to memchr in ldap_bv2dn,
+ * the memchr call walks beyond bv_len and a ldap.DECODING_ERROR is returned.
+ * As a result the ldap.str2dn('c=b,d=k') call fails in python2.4
+ * this happens only under certain conditions...
+ * interactive python2.4: "import ldap; ldap.str2dn('c=b,d=k')" works, but
+ * interactive python2.4: "ldap.str2dn('c=b,d=k')" alone fails.
+ *
+ * A %lu printf of str.bv_len gives values like 139637976727559 in these cases
+ */
+ str.bv_len=str_len;
+
res = ldap_bv2dn(&str, &dn, flags);
if (res != LDAP_SUCCESS)
return LDAPerr(res);
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Python-LDAP-dev mailing list
Python-LDAP-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev