]> granicus.if.org Git - python/commitdiff
Check RefCon backpointer to python object with IsPointerValid() before dereferencing...
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 25 Apr 2001 22:09:29 +0000 (22:09 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 25 Apr 2001 22:09:29 +0000 (22:09 +0000)
Mac/Modules/win/Winmodule.c
Mac/Modules/win/winsupport.py

index 00d58a48ae9d7de17474b514b1a86eeb4714e39a..d2672489e488e0f4793a9c324994effdf1fabfc7 100644 (file)
@@ -15,6 +15,7 @@
 #define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
 #define GetWindowFromPort(port) ((WindowRef)(port))
 #define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
+#define IsPointerValid(p) (((long)p&3) == 0)
 #endif
 #if ACCESSOR_CALLS_ARE_FUNCTIONS
 /* Classic calls that we emulate in carbon mode */
@@ -3038,7 +3039,7 @@ WinObj_WhichWindow(w)
                Py_INCREF(it);
        } else {
                it = (PyObject *) GetWRefCon(w);
-               if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
+               if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
                        it = WinObj_New(w);
                        ((WindowObject *)it)->ob_freeit = NULL;
                } else {
index 6054e263d39b3c73db19d75dffa0da69ebe8fa29..0359a91c6fbde5c3966eac7e437da05d879e07ab 100644 (file)
@@ -61,6 +61,7 @@ includestuff = includestuff + """
 #define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
 #define GetWindowFromPort(port) ((WindowRef)(port))
 #define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
+#define IsPointerValid(p) (((long)p&3) == 0)
 #endif
 #if ACCESSOR_CALLS_ARE_FUNCTIONS
 /* Classic calls that we emulate in carbon mode */
@@ -91,7 +92,7 @@ WinObj_WhichWindow(w)
                Py_INCREF(it);
        } else {
                it = (PyObject *) GetWRefCon(w);
-               if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
+               if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
                        it = WinObj_New(w);
                        ((WindowObject *)it)->ob_freeit = NULL;
                } else {