[pygobject] pygspawn: improve error checking
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] pygspawn: improve error checking
- Date: Tue, 7 Feb 2012 19:59:09 +0000 (UTC)
commit 945fd18e531c2131440af93dcd89f6c63abbfd7c
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Feb 7 13:42:19 2012 -0500
pygspawn: improve error checking
gspawn 'argv' and 'envp' parameters expect sequences of strings. This
is enforced by checking that the passed argument is a sequence and that
each item returned from it is a string.
We do now, however, verify that each item can be successfully taken from
the sequence. 'os.environ' is an example of an object that passes
PySequence_Check() but fails to return objects from PySequence_ITEM().
Add a simple NULL check to avoid the crash.
https://bugzilla.gnome.org/show_bug.cgi?id=669594
gi/_glib/pygspawn.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gi/_glib/pygspawn.c b/gi/_glib/pygspawn.c
index 309b83d..cfa5555 100644
--- a/gi/_glib/pygspawn.c
+++ b/gi/_glib/pygspawn.c
@@ -150,7 +150,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
argv = g_new0(char *, len + 1);
for (i = 0; i < len; ++i) {
PyObject *tmp = PySequence_ITEM(pyargv, i);
- if (!PYGLIB_PyUnicode_Check(tmp)) {
+ if (tmp == NULL || !PYGLIB_PyUnicode_Check(tmp)) {
PyErr_SetString(PyExc_TypeError,
"gi._glib.spawn_async: "
"first argument must be a sequence of strings");
@@ -175,7 +175,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
envp = g_new0(char *, len + 1);
for (i = 0; i < len; ++i) {
PyObject *tmp = PySequence_ITEM(pyenvp, i);
- if (!PYGLIB_PyUnicode_Check(tmp)) {
+ if (tmp == NULL || !PYGLIB_PyUnicode_Check(tmp)) {
PyErr_SetString(PyExc_TypeError,
"gi._glib.spawn_async: "
"second argument must be a sequence of strings");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]