From 3fead8fa3b4fa8451525afaef32fd59e97fecc2b Mon Sep 17 00:00:00 2001 From: Jukka Heinonen Date: Fri, 15 Feb 2002 18:22:23 +0000 Subject: [PATCH] Convert some invalid offsets in GetWindowLong16 into valid offsets. --- windows/win.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/windows/win.c b/windows/win.c index a1d3135d9c7..4572666b8da 100644 --- a/windows/win.c +++ b/windows/win.c @@ -1873,6 +1873,24 @@ static LONG WIN_GetWindowLong( HWND hwnd, INT offset, WINDOWPROCTYPE type ) { if (offset > wndPtr->cbWndExtra - sizeof(LONG)) { + /* + * Some programs try to access last element from 16 bit + * code using illegal offset value. Hopefully this is + * what those programs really expect. + */ + if (type == WIN_PROC_16 && + wndPtr->cbWndExtra >= 4 && + offset == wndPtr->cbWndExtra - sizeof(WORD)) + { + INT offset2 = wndPtr->cbWndExtra - sizeof(LONG); + + ERR( "- replaced invalid offset %d with %d\n", + offset, offset2 ); + + retvalue = *(LONG *)(((char *)wndPtr->wExtra) + offset2); + WIN_ReleasePtr( wndPtr ); + return retvalue; + } WARN("Invalid offset %d\n", offset ); WIN_ReleasePtr( wndPtr ); SetLastError( ERROR_INVALID_INDEX );