s4/auth: Additionally accept unicode as string param in Py2
authorNoel Power <noel.power@suse.com>
Fri, 13 Apr 2018 16:33:10 +0000 (17:33 +0100)
committerNoel Power <npower@samba.org>
Mon, 30 Apr 2018 13:43:19 +0000 (15:43 +0200)
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 <noel.power@suse.com>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
source4/auth/pyauth.c

index 4cb12f882bcc7acf33952416137b8a32a025089a..fc22637564df675dce60c263aa55c97d4e5a4d28 100644 (file)
@@ -184,7 +184,7 @@ static const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
                const char *value;
                Py_ssize_t size;
                PyObject *item = PyList_GetItem(list, i);
-               if (!PyStr_Check(item)) {
+               if (!(PyStr_Check(item) || PyUnicode_Check(item))) {
                        PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
                        return NULL;
                }