summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-04-25 22:09:29 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-04-25 22:09:29 (GMT)
commitc54be4299cd0d784c422755f5535aac623335b85 (patch)
treeb50953bb170256c22033f6ff88c2d80b02a8cd02
parent26e51e1e839dbba270f7b2f7ec2667ac47fbbb75 (diff)
downloadcpython-c54be4299cd0d784c422755f5535aac623335b85.zip
cpython-c54be4299cd0d784c422755f5535aac623335b85.tar.gz
cpython-c54be4299cd0d784c422755f5535aac623335b85.tar.bz2
Check RefCon backpointer to python object with IsPointerValid() before dereferencing it (carbon only).
-rw-r--r--Mac/Modules/win/Winmodule.c3
-rw-r--r--Mac/Modules/win/winsupport.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/Mac/Modules/win/Winmodule.c b/Mac/Modules/win/Winmodule.c
index 00d58a4..d267248 100644
--- a/Mac/Modules/win/Winmodule.c
+++ b/Mac/Modules/win/Winmodule.c
@@ -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 {
diff --git a/Mac/Modules/win/winsupport.py b/Mac/Modules/win/winsupport.py
index 6054e26..0359a91 100644
--- a/Mac/Modules/win/winsupport.py
+++ b/Mac/Modules/win/winsupport.py
@@ -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 {