From: Joel Savitz <jsavitz@redhat.com>
To: linux-gpio@vger.kernel.org
Cc: Joel Savitz <jsavitz@redhat.com>,
fedora-rpi@googlegroups.com,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [libgpiod] bindings: python: fix segfault when calling Line.request()
Date: Tue, 3 Dec 2019 14:23:05 -0500 [thread overview]
Message-ID: <20191203192305.31722-1-jsavitz@redhat.com> (raw)
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
next reply other threads:[~2019-12-03 19:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-03 19:23 Joel Savitz [this message]
2019-12-11 15:11 ` [libgpiod] bindings: python: fix segfault when calling Line.request() Bartosz Golaszewski
2019-12-12 7:56 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191203192305.31722-1-jsavitz@redhat.com \
--to=jsavitz@redhat.com \
--cc=bgolaszewski@baylibre.com \
--cc=fedora-rpi@googlegroups.com \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).