Odd error with sasl_interactive_bind_s

Deepak Giridharagopal deepak at arlut.utexas.edu
Wed Mar 2 21:11:35 CET 2005

Hi, Dave! 

I've reproduced your bug, and I've attached a patch that fixes the
problem. It might interest you to know that this bug doesn't affect more
recent versions of Python, for what that's worth. :)

The long answer:

On Wed, 2005-03-02 at 12:30 -0500, David Hawes wrote:
> Traceback (most recent call last):
>   File "sasl_bind.py", line 69, in ?
>     l.sasl_interactive_bind_s("", sasl_auth)
>   File "/usr/lib/python2.1/site-packages/ldap/ldapobject.py", line 196, in
> sasl_interactive_bind_s    return
> self._ldap_call(self._l.sasl_interactive_bind_s,who,auth,serverctrls,clientctrls
> ,sasl_flags)  
>  File "/usr/lib/python2.1/site-packages/ldap/ldapobject.py", line
> 94, in _ldap_call    
>  result = func(*args,**kwargs)
> TypeError: argument 5 must be impossible<bad format char>, not int

Eek! This looks like a bug in the C code. The function that throws this
error is PyArg_ParseTuple, a C function bundled with Python that takes
Python objects and converts them to vanilla C-types.

The offending bit looks to be lines 648-649 in LDAPObject.c:

if (!PyArg_ParseTuple(args, "sOOOI", &who, &SASLObject, &serverctrls,
&clientctrls, &sasl_flags ))
    return NULL;

The 'sasl_flags' variable is declared as an unsigned int, but it looks
like we're trying to convert it using the "I" flag, which is meant to
convert longs. Replacing that "I" with "i" tells Python to convert that
argument to an int (rather than a long), and it seems to do the trick.

More info on these arcane conversion flags (for the curious):

Don't you just love C programming? :)

The fix makes Python 2.1.3 work again, and the fix doesn't appear to
break anything for more recent versions of Python (which, as I said,
don't seem to suffer from the problem).

Can you try the patch and let me know if it fixes things for you?
Thanks, Dave!


Deepak Giridharagopal
Applied Research Laboratories
University of Texas at Austin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ldap_sasl_typerror_fix.patch
Type: text/x-patch
Size: 596 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20050302/d249ea91/attachment.bin>

More information about the python-ldap mailing list