Since python 3.9, when paring tuple with wrong length fails,
PyObject_Repr() fails when we report the error.
I suspect that the reason is abusing PyArg_ParseTyuple() for parsing a
tuple instead of function argument, or maybe this is a bug in python
3.9.
Checking the tuple size before parsing avoids this issue and helps to
show more helpful error message:
Disk length ~= 2: ('path',)
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index cd6d4b0..0d05ad6 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -161,20 +161,25 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk)
{
int rv = 0;
PyObject *path = NULL;
uint64_t offset;
if (!PyTuple_Check(disk)) {
set_error(PyExc_ValueError, "Disk is not a tuple: %s", disk);
goto finally;
}
+ if (PyTuple_Size(disk) != 2) {
+ set_error(PyExc_ValueError, "Disk length != 2: %s", disk);
+ goto finally;
+ }
+
if (!PyArg_ParseTuple(disk, "O&K", pypath_converter, &path,
&offset)) {
/* Override the error since it confusing in this context. */
set_error(PyExc_ValueError, "Cannot parse disk: %s", disk);
goto finally;
}
if (!validate_path(path))
goto finally;
strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
--
2.38.1