python: py_strcasecmp_m & py_strstr_m don't handle unicode properly
authorNoel Power <noel.power@suse.com>
Tue, 7 Aug 2018 15:21:35 +0000 (16:21 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 23 Oct 2018 03:50:26 +0000 (05:50 +0200)
py_strcasecmp_m & py_strstr_m use PyArg_ParseTuple() with 's' which
in Py2 tries to decode string with the default (e.g. ascii) encoding

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/pyglue.c

index 1b111866f223652a6a6796cc7e8a0a01a3f6986d..04efa14d0513eaf1ed4be8de4e5ebd713c179c23 100644 (file)
@@ -297,26 +297,30 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
 
 static PyObject *py_strcasecmp_m(PyObject *self, PyObject *args)
 {
-       char *s1, *s2;
+       const char *s1 = NULL;
+       const char *s2 = NULL;
 
-       if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
+       if (!PyArg_ParseTuple(args, "eses", "utf8", &s1, "utf8", &s2)) {
                return NULL;
+       }
 
        return PyInt_FromLong(strcasecmp_m(s1, s2));
 }
 
 static PyObject *py_strstr_m(PyObject *self, PyObject *args)
 {
-       char *s1, *s2, *ret;
+       const char *s1 = NULL;
+       const char *s2 = NULL;
+       char *ret = NULL;
 
-       if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
+       if (!PyArg_ParseTuple(args, "eses", "utf8", &s1, "utf8", &s2))
                return NULL;
 
        ret = strstr_m(s1, s2);
        if (!ret) {
                Py_RETURN_NONE;
        }
-       return PyStr_FromString(ret);
+       return PyUnicode_FromString(ret);
 }
 
 static PyMethodDef py_misc_methods[] = {