Author: tkreuzer Date: Sun Mar 8 23:36:14 2015 New Revision: 66614
URL: http://svn.reactos.org/svn/reactos?rev=66614&view=rev Log: [WIN32K] Make sure a region is reasonably initialized, before potentially passing it to the cleanup function, when failing to create a handle.
Modified: trunk/reactos/win32ss/gdi/ntgdi/region.c
Modified: trunk/reactos/win32ss/gdi/ntgdi/region.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/region.c?... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/region.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/region.c [iso-8859-1] Sun Mar 8 23:36:14 2015 @@ -2187,13 +2187,6 @@ return NULL; }
- if (!GDIOBJ_hInsertObject(&pReg->BaseObject, GDI_OBJ_HMGR_POWNED)) - { - DPRINT1("Could not insert palette into handle table.\n"); - GDIOBJ_vFreeObject(&pReg->BaseObject); - return NULL; - } - //hReg = pReg->BaseObject.hHmgr;
if ((nReg == 0) || (nReg == 1)) @@ -2221,6 +2214,19 @@ pReg->rdh.nRgnSize = nReg * sizeof(RECT); pReg->prgnattr = &pReg->rgnattr;
+ /* Initialize the region attribute */ + pReg->rgnattr.AttrFlags = 0; + pReg->rgnattr.iComplexity = SIMPLEREGION; + pReg->rgnattr.Rect = pReg->rdh.rcBound; + + /* Finally insert the region into the handle table */ + if (!GDIOBJ_hInsertObject(&pReg->BaseObject, GDI_OBJ_HMGR_POWNED)) + { + DPRINT1("Could not insert palette into handle table.\n"); + GDIOBJ_vFreeObject(&pReg->BaseObject); + return NULL; + } + return pReg; }
@@ -2232,6 +2238,8 @@ PPROCESSINFO ppi; PRGN_ATTR prgnattr;
+ NT_ASSERT(prgn->prgnattr == &prgn->rgnattr); + ppi = PsGetCurrentProcessWin32Process(); ASSERT(ppi);
@@ -2241,6 +2249,9 @@ DPRINT1("Could not allocate RGN attr\n"); return FALSE; } + + /* Copy the current region attribute */ + *prgnattr = prgn->rgnattr;
/* Set the object attribute in the handle table */ prgn->prgnattr = prgnattr; @@ -3928,105 +3939,112 @@ INT APIENTRY NtGdiOffsetRgn( - HRGN hRgn, - INT XOffset, - INT YOffset) -{ - PREGION rgn; - INT ret; - - DPRINT("NtGdiOffsetRgn: hRgn %p Xoffs %d Yoffs %d rgn %p\n", hRgn, XOffset, YOffset, rgn ); - - rgn = REGION_LockRgn(hRgn); - if (rgn == NULL) - { - DPRINT("NtGdiOffsetRgn: hRgn error\n"); + _In_ HRGN hrgn, + _In_ INT cx, + _In_ INT cy) +{ + PREGION prgn; + INT iResult; + + DPRINT("NtGdiOffsetRgn: hrgn %p cx %d cy %d\n", hrgn, cx, cy); + + /* Lock the region */ + prgn = REGION_LockRgn(hrgn); + if (prgn == NULL) + { + DPRINT1("NtGdiOffsetRgn: failed to lock region %p\n", hrgn); return ERROR; }
- if (!REGION_bOffsetRgn(rgn, XOffset, YOffset)) - { - ret = ERROR; + /* Call the internal function */ + if (!REGION_bOffsetRgn(prgn, cx, cy)) + { + iResult = ERROR; } else { - ret = REGION_Complexity(rgn); - } - - REGION_UnlockRgn(rgn); - return ret; + iResult = REGION_Complexity(prgn); + } + + /* Unlock and return the result */ + REGION_UnlockRgn(prgn); + return iResult; }
BOOL APIENTRY NtGdiPtInRegion( - HRGN hRgn, - INT X, - INT Y) + _In_ HRGN hrgn, + _In_ INT x, + _In_ INT y) { PREGION prgn; - BOOL ret; - - prgn = REGION_LockRgn(hRgn); + BOOL bResult; + + /* Lock the region */ + prgn = REGION_LockRgn(hrgn); if (prgn == NULL) + { + DPRINT1("NtGdiPtInRegion: hrgn error\n"); return FALSE; - - ret = REGION_PtInRegion(prgn, X, Y); - + } + + /* Call the internal function */ + bResult = REGION_PtInRegion(prgn, x, y); + + /* Unlock and return the result */ REGION_UnlockRgn(prgn); - return ret; + return bResult; }
BOOL APIENTRY NtGdiRectInRegion( - HRGN hRgn, - LPRECTL unsaferc) -{ - RECTL rc = { 0 }; - NTSTATUS Status = STATUS_SUCCESS; - + _In_ HRGN hrgn, + _In_ LPRECT prclUnsafe) +{ + RECTL rcTemp; + + /* Probe and copy the rect */ _SEH2_TRY { - ProbeForRead(unsaferc, sizeof(RECT), 1); - rc = *unsaferc; + ProbeForRead(prclUnsafe, sizeof(RECT), 1); + rcTemp = *prclUnsafe; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - Status = _SEH2_GetExceptionCode(); + DPRINT1("NtGdiRectInRegion: Exception accessing the rect\n"); + return FALSE; } _SEH2_END;
- if (!NT_SUCCESS(Status)) - { - SetLastNtError(Status); - DPRINT1("NtGdiRectInRegion: Bogus rc\n"); - return ERROR; - } - - return IntRectInRegion(hRgn, &rc); + /* Call the internal function */ + return IntRectInRegion(hrgn, &rcTemp); }
BOOL APIENTRY NtGdiSetRectRgn( - HRGN hRgn, - INT LeftRect, - INT TopRect, - INT RightRect, - INT BottomRect) -{ - PREGION rgn; - - rgn = REGION_LockRgn(hRgn); - if (rgn == NULL) - { - return 0; // Per documentation - } - - REGION_SetRectRgn(rgn, LeftRect, TopRect, RightRect, BottomRect); - - REGION_UnlockRgn(rgn); + _In_ HRGN hrgn, + _In_ INT xLeft, + _In_ INT yTop, + _In_ INT xRight, + _In_ INT yBottom) +{ + PREGION prgn; + + /* Lock the region */ + prgn = REGION_LockRgn(hrgn); + if (prgn == NULL) + { + return FALSE; + } + + /* Call the internal API */ + REGION_SetRectRgn(prgn, xLeft, yTop, xRight, yBottom); + + /* Unlock the region and return success */ + REGION_UnlockRgn(prgn); return TRUE; }