1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00

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 <jsavitz@redhat.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
This commit is contained in:
Joel Savitz
2019-12-03 14:23:05 -05:00
committed by Bartosz Golaszewski
parent 3e30364cc1
commit 02a3d0a2ab

View File

@@ -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,