From: Noel Power Date: Tue, 7 Aug 2018 15:21:35 +0000 (+0100) Subject: python: py_strcasecmp_m & py_strstr_m don't handle unicode properly X-Git-Tag: tdb-1.3.17~1249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23239727734bbc7f58dcba3d8e9f160849885276;p=thirdparty%2Fsamba.git python: py_strcasecmp_m & py_strstr_m don't handle unicode properly 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 Reviewed-by: Andrew Bartlett --- diff --git a/python/pyglue.c b/python/pyglue.c index 1b111866f22..04efa14d051 100644 --- a/python/pyglue.c +++ b/python/pyglue.c @@ -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[] = {