diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2013-10-04 13:42:34 -0700 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2013-10-07 14:41:28 -0700 |
commit | 0120af6c418d0f67f39c02a4e8327813645b97f4 (patch) | |
tree | f680e7d42256d50da954bddf595042738eee1083 /gi/pygi-info.c | |
parent | c86b2fe8d01070f06c45fffd910d890afba1313a (diff) | |
download | pygobject-0120af6c418d0f67f39c02a4e8327813645b97f4.tar.gz |
Avoid calling g_base_info_get_name on GI_INFO_TYPE_TYPE
Calling g_base_info_get_name on infos tagged with GI_INFO_TYPE_TYPE will
cause a crash. Avoid this by adding _safe_base_info_get_name and using that
throughout the bindings.
Logged GI bug as: https://bugzilla.gnome.org/show_bug.cgi?id=709456
https://bugzilla.gnome.org/show_bug.cgi?id=709008
Diffstat (limited to 'gi/pygi-info.c')
-rw-r--r-- | gi/pygi-info.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/gi/pygi-info.c b/gi/pygi-info.c index 30c6a7a3..c087cb6d 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -129,6 +129,20 @@ _make_infos_tuple (PyGIBaseInfo *self, /* BaseInfo */ +/* We need to be careful about calling g_base_info_get_name because + * calling it with a GI_INFO_TYPE_TYPE will crash. + * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456 + */ +static const char * +_safe_base_info_get_name (GIBaseInfo *info) +{ + if (g_base_info_get_type (info) == GI_INFO_TYPE_TYPE) { + return "type_type_instance"; + } else { + return g_base_info_get_name (info); + } +} + static void _base_info_dealloc (PyGIBaseInfo *self) { @@ -145,9 +159,10 @@ _base_info_dealloc (PyGIBaseInfo *self) static PyObject * _base_info_repr (PyGIBaseInfo *self) { + return PYGLIB_PyUnicode_FromFormat ("<%s object (%s) at 0x%p>", - Py_TYPE( (PyObject *) self)->tp_name, - g_base_info_get_name (self->info), + Py_TYPE( (PyObject *) self)->tp_name, + _safe_base_info_get_name (self->info), (void *) self); } @@ -237,7 +252,7 @@ _wrap_g_base_info_get_name (PyGIBaseInfo *self) { const gchar *name; - name = g_base_info_get_name (self->info); + name = _safe_base_info_get_name (self->info); /* escape keywords */ if (_pygi_is_python_keyword (name)) { @@ -253,7 +268,7 @@ _wrap_g_base_info_get_name (PyGIBaseInfo *self) static PyObject * _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self) { - return _get_info_string (self, g_base_info_get_name); + return _get_info_string (self, _safe_base_info_get_name); } static PyObject * @@ -540,11 +555,11 @@ _function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs) str_name = PyBytes_AsString (py_str_name); #endif - if (strcmp (str_name, g_base_info_get_name (container_info))) { + if (strcmp (str_name, _safe_base_info_get_name (container_info))) { PyErr_Format (PyExc_TypeError, "%s constructor cannot be used to create instances of " "a subclass %s", - g_base_info_get_name (container_info), + _safe_base_info_get_name (container_info), str_name); Py_DECREF (py_str_name); return NULL; @@ -744,7 +759,7 @@ _g_arg_get_pytype_hint (PyGIBaseInfo *self) GIBaseInfo *iface = g_type_info_get_interface(&type_info); gchar *name; - info_name = g_base_info_get_name (iface); + info_name = _safe_base_info_get_name (iface); if (info_name == NULL) { g_base_info_unref (iface); return PYGLIB_PyUnicode_FromString(g_type_tag_to_string(type_tag)); @@ -1625,12 +1640,12 @@ _pygi_g_base_info_get_fullname (GIBaseInfo *info) if (container_info != NULL) { fullname = g_strdup_printf ("%s.%s.%s", g_base_info_get_namespace (container_info), - g_base_info_get_name (container_info), - g_base_info_get_name (info)); + _safe_base_info_get_name (container_info), + _safe_base_info_get_name (info)); } else { fullname = g_strdup_printf ("%s.%s", g_base_info_get_namespace (info), - g_base_info_get_name (info)); + _safe_base_info_get_name (info)); } if (fullname == NULL) { |