diff --git a/Modules/functions.c b/Modules/functions.c index f7d9cf37..72d83513 100644 --- a/Modules/functions.c +++ b/Modules/functions.c @@ -100,6 +100,11 @@ l_ldap_str2dn(PyObject *unused, PyObject *args) */ if (!PyArg_ParseTuple(args, "z#|i:str2dn", &str.bv_val, &str_len, &flags)) return NULL; + + if (str_len == 0) { + // GH-549: ldap_bv2dn() does not support empty string. + return PyList_New(0); + } str.bv_len = (ber_len_t) str_len; res = ldap_bv2dn(&str, &dn, flags); diff --git a/Tests/t_cext.py b/Tests/t_cext.py index 33fbf29a..9df16dc8 100644 --- a/Tests/t_cext.py +++ b/Tests/t_cext.py @@ -955,6 +955,12 @@ def test_require_san(self): _ldap.OPT_X_TLS_TRY ) + def test_str2dn(self): + self.assertEqual(_ldap.str2dn(""), []) + self.assertEqual(_ldap.str2dn(None), []) + with self.assertRaises(TypeError): + _ldap.str2dn(object) + if __name__ == '__main__': unittest.main()