This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master in repository sanlock.
commit e24d87a6501e2d93575ebda902b56fd9a68e1747 Author: Amit Bawer abawer@redhat.com AuthorDate: Sun Jun 2 17:25:26 2019 +0300
python: Use PyBytes converter for resource owner request API
Implications:
- Py2 : no difference - Py3 : if used, only accept bytes for lockspace/resource name. --- python/sanlock.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index b43d635..0964671 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1159,28 +1159,29 @@ The disks must be in the format: [(path, offset), ... ]"); static PyObject * py_request(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv, action = SANLK_REQ_GRACEFUL, flags = 0; - const char *lockspace, *resource; - struct sanlk_resource *res; + int rv = -1, action = SANLK_REQ_GRACEFUL, flags = 0; + PyObject *lockspace = NULL, *resource = NULL; + struct sanlk_resource *res = NULL; PyObject *disks, *version = Py_None;
static char *kwlist[] = {"lockspace", "resource", "disks", "action", "version", NULL};
/* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iO", kwlist, - &lockspace, &resource, &PyList_Type, &disks, &action, &version)) { - return NULL; + if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iO", kwlist, + convert_to_pybytes, &lockspace, convert_to_pybytes, &resource, + &PyList_Type, &disks, &action, &version)) { + goto finally; }
/* parse and check sanlock resource */ if (__parse_resource(disks, &res) < 0) { - return NULL; + goto finally; }
/* prepare sanlock names */ - strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN); - strncpy(res->name, resource, SANLK_NAME_LEN); + strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN); + strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* prepare the resource version */ if (version == Py_None) { @@ -1190,7 +1191,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds) res->lver = pyinteger_as_unsigned_long_long_mask(version); if (res->lver == (uint64_t)-1) { __set_exception(EINVAL, "Unable to convert the version value"); - goto exit_fail; + goto finally; } }
@@ -1201,15 +1202,16 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) { __set_exception(rv, "Sanlock request not submitted"); - goto exit_fail; + goto finally; }
+finally: + Py_XDECREF(lockspace); + Py_XDECREF(resource); free(res); + if (rv != 0) + return NULL; Py_RETURN_NONE; - -exit_fail: - free(res); - return NULL; }
/* read_resource_owners */
sanlock-devel@lists.fedorahosted.org