From: Noel Power Date: Fri, 13 Apr 2018 16:34:40 +0000 (+0100) Subject: s4/param: Additionally accept unicode as string param in Py2 X-Git-Tag: ldb-1.4.0~510 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=ba5f00deb772b76719bfd06467a6b05edfeef061;p=samba.git s4/param: Additionally accept unicode as string param in Py2 With the changes to make samba python code Py2/Py3 compatible there now are many instances where string content is decoded. Decoded string variables in Py2 are returned as the unicode type. Many Py2 c-module functions that take string arguments only check for the string type. However now it's quite possibe the content formally passed as a string argument is now passed as unicode after being decoded, such arguments are rejected and code can fail subtly. This only affects places where the type is directly checked e.g. via PyStr_Check etc. arguments that are parsed by ParseTuple* functions generally already accept both string and unicode (if 's', 'z', 's*' format specifiers are used) Signed-off-by: Noel Power Reviewed-by: Alexander Bokovoy --- diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index 18d7017b9c6..e7e908fcac3 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -456,7 +456,7 @@ static Py_ssize_t py_lp_ctx_len(PyObject *self) static PyObject *py_lp_ctx_getitem(PyObject *self, PyObject *name) { struct loadparm_service *service; - if (!PyStr_Check(name)) { + if (!(PyStr_Check(name) || PyUnicode_Check(name))) { PyErr_SetString(PyExc_TypeError, "Only string subscripts are supported"); return NULL; } diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c index 512a8b1cdb7..917caf809e5 100644 --- a/source4/param/pyparam_util.c +++ b/source4/param/pyparam_util.c @@ -34,7 +34,7 @@ _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyOb PyTypeObject *lp_type; bool is_lpobj; - if (PyStr_Check(py_obj)) { + if (PyStr_Check(py_obj) || PyUnicode_Check(py_obj)) { lp_ctx = loadparm_init_global(false); if (lp_ctx == NULL) { return NULL;