I've now tried a trivially modified version of the original submitter's test script (replacing his LDAP server and DN with mine), and can confirm that (a) I can reproduce the bug, and (b) after applying my patch the test script prints "success".