* [libgpiod] bindings: python: fix segfault when calling Line.request()
@ 2019-12-03 19:23 Joel Savitz
2019-12-11 15:11 ` Bartosz Golaszewski
2019-12-12 7:56 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Joel Savitz @ 2019-12-03 19:23 UTC (permalink / raw)
To: linux-gpio; +Cc: Joel Savitz, fedora-rpi, Bartosz Golaszewski
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>
---
bindings/python/gpiodmodule.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
index 2f6ef51..ae7e1cc 100644
--- a/bindings/python/gpiodmodule.c
+++ b/bindings/python/gpiodmodule.c
@@ -434,8 +434,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,
--
2.23.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [libgpiod] bindings: python: fix segfault when calling Line.request()
2019-12-03 19:23 [libgpiod] bindings: python: fix segfault when calling Line.request() Joel Savitz
@ 2019-12-11 15:11 ` Bartosz Golaszewski
2019-12-12 7:56 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-12-11 15:11 UTC (permalink / raw)
To: Joel Savitz; +Cc: linux-gpio, fedora-rpi
wt., 3 gru 2019 o 20:24 Joel Savitz <jsavitz@redhat.com> napisał(a):
>
> 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>
> ---
> bindings/python/gpiodmodule.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
> index 2f6ef51..ae7e1cc 100644
> --- a/bindings/python/gpiodmodule.c
> +++ b/bindings/python/gpiodmodule.c
> @@ -434,8 +434,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,
> --
> 2.23.0
>
Applied to master and 1.4.x stable.
Thanks,
Bartosz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [libgpiod] bindings: python: fix segfault when calling Line.request()
2019-12-03 19:23 [libgpiod] bindings: python: fix segfault when calling Line.request() Joel Savitz
2019-12-11 15:11 ` Bartosz Golaszewski
@ 2019-12-12 7:56 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-12-12 7:56 UTC (permalink / raw)
To: Joel Savitz; +Cc: open list:GPIO SUBSYSTEM, fedora-rpi, Bartosz Golaszewski
wt., 3 gru 2019 o 20:24 Joel Savitz <jsavitz@redhat.com> napisał(a):
>
> 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>
> ---
> bindings/python/gpiodmodule.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
> index 2f6ef51..ae7e1cc 100644
> --- a/bindings/python/gpiodmodule.c
> +++ b/bindings/python/gpiodmodule.c
> @@ -434,8 +434,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,
> --
> 2.23.0
>
Thanks a lot for bringing this to my attention - I wasn't aware that
the kwds dictionary will be NULL if no named arguments were passed to
the function call. Let me know if you see any such bug anywhere else.
I've looked through the code but this seems to be the only place where
I ever access the dictionary directly.
Best regards,
Bartosz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-12 7:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03 19:23 [libgpiod] bindings: python: fix segfault when calling Line.request() Joel Savitz
2019-12-11 15:11 ` Bartosz Golaszewski
2019-12-12 7:56 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).