[pygobject] check if object is actually a PyGFlag before trying to access g_type
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] check if object is actually a PyGFlag before trying to access g_type
- Date: Tue, 13 Sep 2011 20:10:41 +0000 (UTC)
commit 861369ec59b17f67151813dc2e87c6e86126b954
Author: John (J5) Palmieri <johnp redhat com>
Date: Tue Sep 13 16:04:31 2011 -0400
check if object is actually a PyGFlag before trying to access g_type
* we are lucky this bit of code worked for as long as it did but when
checking if an object is a PyGFlag we can't just rely on looking
at the g_type field because if a regular gobject is passed in
as is the case when you compare a long to a gflag, the gobject
will not have a g_type field. Accessing a non-existant field
could at best give you a false positive and at worse read
memory beyond the bounds of the actual structure passed in
gi/_gobject/pygobject-private.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gi/_gobject/pygobject-private.h b/gi/_gobject/pygobject-private.h
index 38a5b64..0166825 100644
--- a/gi/_gobject/pygobject-private.h
+++ b/gi/_gobject/pygobject-private.h
@@ -184,7 +184,7 @@ typedef struct {
extern PyTypeObject PyGFlags_Type;
-#define PyGFlags_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
+#define PyGFlags_Check(x) (PyObject_IsInstance(x, &PyGFlags_Type) && g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
extern PyObject * pyg_flags_add (PyObject * module,
const char * type_name,
@@ -194,7 +194,7 @@ extern PyObject * pyg_flags_from_gtype (GType gtype,
int value);
/* pygenum */
-#define PyGEnum_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
+#define PyGEnum_Check(x) (PyObject_IsInstance(x, &PyGEnum_Type) && g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
typedef struct {
PYGLIB_PyLongObject parent;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]