[pygobject] Fix crash in GLib.find_program_in_path()



commit 379c1474a071292a1e8da413af2f5438cff09fc8
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Jun 20 12:23:12 2012 +0200

    Fix crash in GLib.find_program_in_path()
    
    We need to handle a NULL return value properly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678119

 gi/_glib/glibmodule.c |   10 ++++++++--
 tests/Makefile.am     |    1 +
 tests/test_glib.py    |   15 +++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index f01ee77..2db764b 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -598,8 +598,14 @@ pyglib_find_program_in_path(PyObject *unused, PyObject *args, PyObject *kwargs)
         return NULL;
 
     ret = g_find_program_in_path(program);
-    retval = PYGLIB_PyUnicode_FromString(ret);
-    g_free(ret);
+
+    if (ret != NULL) {
+        retval = PYGLIB_PyUnicode_FromString(ret);
+        g_free(ret);
+    } else {
+        Py_INCREF(Py_None);
+        retval = Py_None;
+    }
     return retval;
 }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b2390a..92adc3c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ EXTRA_DIST = \
 	test-unknown.h \
 	te_ST nouppera \
 	org.gnome.test.gschema.xml \
+	test_glib.py \
 	test_gobject.py \
 	test_interface.py \
 	test_mainloop.py \
diff --git a/tests/test_glib.py b/tests/test_glib.py
new file mode 100644
index 0000000..a36eca6
--- /dev/null
+++ b/tests/test_glib.py
@@ -0,0 +1,15 @@
+# -*- Mode: Python -*-
+
+import unittest
+import os.path
+
+from gi.repository import GLib
+
+
+class TestGLib(unittest.TestCase):
+    def test_find_program_in_path(self):
+        bash_path = GLib.find_program_in_path('bash')
+        self.assertTrue(bash_path.endswith('/bash'))
+        self.assertTrue(os.path.exists(bash_path))
+
+        self.assertEqual(GLib.find_program_in_path('non existing'), None)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]