summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2018-04-13 17:32:15 +0100
committerNoel Power <npower@samba.org>2018-04-30 15:43:19 +0200
commit7020af427ecb923015ba07ede45d4bb282db25e4 (patch)
tree027dd649db41c18100c6de5b63e5e06e18c9fc0f /libcli
parent702e85e48fc4972714c57683f4c7b1daf775bd5c (diff)
downloadsamba-7020af427ecb923015ba07ede45d4bb282db25e4.tar.gz
libcli/nbt: 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 <noel.power@suse.com> Reviewed-by: Alexander Bokovoy <ab@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r--libcli/nbt/pynbt.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/libcli/nbt/pynbt.c b/libcli/nbt/pynbt.c
index 254c98a4b89..032561a4bd8 100644
--- a/libcli/nbt/pynbt.c
+++ b/libcli/nbt/pynbt.c
@@ -57,7 +57,7 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *
static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
{
- if (PyStr_Check(obj)) {
+ if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
*dest_addr = PyStr_AsString(obj);
*dest_port = NBT_NAME_SERVICE_PORT;
return true;
@@ -69,7 +69,7 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u
return false;
}
- if (!PyStr_Check(PyTuple_GetItem(obj, 0))) {
+ if (!(PyStr_Check(PyTuple_GetItem(obj, 0)) || PyUnicode_Check(PyTuple_GetItem(obj, 0)))) {
PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
return false;
}
@@ -111,7 +111,7 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
}
}
- if (PyStr_Check(obj)) {
+ if (PyStr_Check(obj) || PyUnicode_Check(obj)) {
/* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
name->name = PyStr_AsString(obj);
name->scope = NULL;