From: Joel Savitz Date: Tue, 3 Dec 2019 19:23:05 +0000 (-0500) Subject: bindings: python: fix segfault when calling Line.request() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=02a3d0a2ab5ec6184114629a06b7c3456a706f9e;p=qemu-gpiodev%2Flibgpiod.git bindings: python: fix segfault when calling Line.request() When Line.request() is called without the required 'consumer=value' argument, the module attempts access an empty dictionary object resulting in a segfault. This patch avoids such access when the dictionary is empty and maintains the current design where the LineBulk object is responsible for validation of arguments. Signed-off-by: Joel Savitz Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 00f624b..27a8118 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -472,8 +472,12 @@ static PyObject *gpiod_Line_request(gpiod_LineObject *self, gpiod_LineBulkObject *bulk_obj; int rv; - def_val = PyDict_GetItemString(kwds, "default_val"); - def_vals = PyDict_GetItemString(kwds, "default_vals"); + if (PyDict_Size(kwds) > 0) { + def_val = PyDict_GetItemString(kwds, "default_val"); + def_vals = PyDict_GetItemString(kwds, "default_vals"); + } else { + def_val = def_vals = NULL; + } if (def_val && def_vals) { PyErr_SetString(PyExc_TypeError,