Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c54be42

Browse files
committed
Check RefCon backpointer to python object with IsPointerValid() before dereferencing it (carbon only).
1 parent 26e51e1 commit c54be42

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Mac/Modules/win/Winmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
1616
#define GetWindowFromPort(port) ((WindowRef)(port))
1717
#define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
18+
#define IsPointerValid(p) (((long)p&3) == 0)
1819
#endif
1920
#if ACCESSOR_CALLS_ARE_FUNCTIONS
2021
/* Classic calls that we emulate in carbon mode */
@@ -3038,7 +3039,7 @@ WinObj_WhichWindow(w)
30383039
Py_INCREF(it);
30393040
} else {
30403041
it = (PyObject *) GetWRefCon(w);
3041-
if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
3042+
if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
30423043
it = WinObj_New(w);
30433044
((WindowObject *)it)->ob_freeit = NULL;
30443045
} else {

Mac/Modules/win/winsupport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define GetWindowSpareFlag(win) (((CWindowPeek)(win))->spareFlag)
6262
#define GetWindowFromPort(port) ((WindowRef)(port))
6363
#define GetWindowPortBounds(win, rectp) (*(rectp) = ((CWindowPeek)(win))->port.portRect)
64+
#define IsPointerValid(p) (((long)p&3) == 0)
6465
#endif
6566
#if ACCESSOR_CALLS_ARE_FUNCTIONS
6667
/* Classic calls that we emulate in carbon mode */
@@ -91,7 +92,7 @@
9192
Py_INCREF(it);
9293
} else {
9394
it = (PyObject *) GetWRefCon(w);
94-
if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
95+
if (it == NULL || !IsPointerValid((Ptr)it) || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
9596
it = WinObj_New(w);
9697
((WindowObject *)it)->ob_freeit = NULL;
9798
} else {

0 commit comments

Comments
 (0)