- Add/improve some annotations
- Improve code in EngpGetPDEV and NtGdiGetRegionData
- Simplify SEH exception handling
- Fix possible NULL pointer dereferences
- Fix wrong variable usage in UnpackParam
- Fix a possible bufer overrun
- Check return value of ExAllocatePool and RtlCreateUnicodeString
- Fix & vs && typo
All detected with VS11 analyse

svn path=/trunk/; revision=57948
This commit is contained in:
Timo Kreuzer 2012-12-18 21:44:58 +00:00
parent e3cf3471d2
commit e61a4d3fcb
31 changed files with 290 additions and 211 deletions

View file

@ -1996,6 +1996,7 @@ NtGdiGetDCDword(
OUT DWORD *Result OUT DWORD *Result
); );
_Success_(return!=FALSE)
W32KAPI W32KAPI
BOOL BOOL
APIENTRY APIENTRY
@ -2046,6 +2047,7 @@ NtGdiSetSizeDevice(
_In_ INT cxVirtualDevice, _In_ INT cxVirtualDevice,
_In_ INT cyVirtualDevice); _In_ INT cyVirtualDevice);
_Success_(return !=FALSE)
W32KAPI W32KAPI
BOOL BOOL
APIENTRY APIENTRY
@ -2508,6 +2510,7 @@ NtGdiOffsetRgn(
_In_ INT cx, _In_ INT cx,
_In_ INT cy); _In_ INT cy);
_Success_(return!=ERROR)
W32KAPI W32KAPI
INT INT
APIENTRY APIENTRY
@ -2523,6 +2526,7 @@ NtGdiRectInRegion(
IN OUT LPRECT prcl IN OUT LPRECT prcl
); );
_Success_(return!=0)
W32KAPI W32KAPI
DWORD DWORD
APIENTRY APIENTRY
@ -2559,13 +2563,14 @@ NtGdiSetSystemPaletteUse(
_In_ HDC hdc, _In_ HDC hdc,
_In_ UINT ui); _In_ UINT ui);
_Success_(return!=0)
W32KAPI W32KAPI
DWORD ULONG
APIENTRY APIENTRY
NtGdiGetRegionData( NtGdiGetRegionData(
_In_ HRGN hrgn, _In_ HRGN hrgn,
_In_ DWORD nCount, _In_ ULONG cjBuffer,
_Out_opt_ LPRGNDATA lpRgnData); _Out_opt_bytecap_(cjBuffer) LPRGNDATA lpRgnData);
W32KAPI W32KAPI
BOOL BOOL

View file

@ -472,7 +472,7 @@ leave:
PPDEVOBJ PPDEVOBJ
NTAPI NTAPI
EngpGetPDEV( EngpGetPDEV(
_In_ PUNICODE_STRING pustrDeviceName) _In_opt_ PUNICODE_STRING pustrDeviceName)
{ {
UNICODE_STRING ustrCurrent; UNICODE_STRING ustrCurrent;
PPDEVOBJ ppdev; PPDEVOBJ ppdev;
@ -481,37 +481,39 @@ EngpGetPDEV(
/* Acquire PDEV lock */ /* Acquire PDEV lock */
EngAcquireSemaphore(ghsemPDEV); EngAcquireSemaphore(ghsemPDEV);
/* If no device name is given, ... */ /* Did the caller pass a device name? */
if (!pustrDeviceName && gppdevPrimary) if (pustrDeviceName)
{ {
/* ... use the primary PDEV */ /* Loop all present PDEVs */
ppdev = gppdevPrimary; for (ppdev = gppdevList; ppdev; ppdev = ppdev->ppdevNext)
/* Reference the pdev */
InterlockedIncrement(&ppdev->cPdevRefs);
goto leave;
}
/* Loop all present PDEVs */
for (ppdev = gppdevList; ppdev; ppdev = ppdev->ppdevNext)
{
/* Get a pointer to the GRAPHICS_DEVICE */
pGraphicsDevice = ppdev->pGraphicsDevice;
/* Compare the name */
RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
if (RtlEqualUnicodeString(pustrDeviceName, &ustrCurrent, FALSE))
{ {
/* Found! Reference the PDEV */ /* Get a pointer to the GRAPHICS_DEVICE */
InterlockedIncrement(&ppdev->cPdevRefs); pGraphicsDevice = ppdev->pGraphicsDevice;
break;
/* Compare the name */
RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
if (RtlEqualUnicodeString(pustrDeviceName, &ustrCurrent, FALSE))
{
/* Found! */
break;
}
} }
} }
else
{
/* Otherwise use the primary PDEV */
ppdev = gppdevPrimary;
}
/* Did we find one? */ /* Did we find one? */
if (!ppdev) if (ppdev)
{ {
/* No, create a new PDEV */ /* Yes, reference the PDEV */
InterlockedIncrement(&ppdev->cPdevRefs);
}
else
{
/* No, create a new PDEV for the given device */
ppdev = EngpCreatePDEV(pustrDeviceName, NULL); ppdev = EngpCreatePDEV(pustrDeviceName, NULL);
if (ppdev) if (ppdev)
{ {
@ -528,7 +530,6 @@ EngpGetPDEV(
} }
} }
leave:
/* Release PDEV lock */ /* Release PDEV lock */
EngReleaseSemaphore(ghsemPDEV); EngReleaseSemaphore(ghsemPDEV);

View file

@ -161,7 +161,7 @@ extern PPDEVOBJ gppdevPrimary;
PPDEVOBJ PPDEVOBJ
NTAPI NTAPI
EngpGetPDEV( EngpGetPDEV(
_In_ PUNICODE_STRING pustrDevice); _In_opt_ PUNICODE_STRING pustrDevice);
VOID VOID
NTAPI NTAPI
@ -188,6 +188,6 @@ PSIZEL
FASTCALL FASTCALL
PDEVOBJ_sizl( PDEVOBJ_sizl(
_In_ PPDEVOBJ ppdev, _In_ PPDEVOBJ ppdev,
_In_ PSIZEL psizl); _Out_ PSIZEL psizl);
#endif /* !__WIN32K_PDEVOBJ_H */ #endif /* !__WIN32K_PDEVOBJ_H */

View file

@ -11,6 +11,13 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
_Always_(_Post_satisfies_(return==iColor))
_Function_class_(FN_XLATE)
ULONG
FASTCALL
EXLATEOBJ_iXlateTrivial(
_In_ PEXLATEOBJ pexlo,
_In_ ULONG iColor);
/** Globals *******************************************************************/ /** Globals *******************************************************************/
@ -31,6 +38,8 @@ static const BYTE gajXlate6to8[64] =
/** iXlate functions **********************************************************/ /** iXlate functions **********************************************************/
_Always_(_Post_satisfies_(return==iColor))
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateTrivial(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateTrivial(PEXLATEOBJ pexlo, ULONG iColor)
@ -38,6 +47,7 @@ EXLATEOBJ_iXlateTrivial(PEXLATEOBJ pexlo, ULONG iColor)
return iColor; return iColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateToMono(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateToMono(PEXLATEOBJ pexlo, ULONG iColor)
@ -45,6 +55,7 @@ EXLATEOBJ_iXlateToMono(PEXLATEOBJ pexlo, ULONG iColor)
return (iColor == pexlo->xlo.pulXlate[0]); return (iColor == pexlo->xlo.pulXlate[0]);
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateTable(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateTable(PEXLATEOBJ pexlo, ULONG iColor)
@ -53,6 +64,7 @@ EXLATEOBJ_iXlateTable(PEXLATEOBJ pexlo, ULONG iColor)
return pexlo->xlo.pulXlate[iColor]; return pexlo->xlo.pulXlate[iColor];
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateRGBtoBGR(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlateRGBtoBGR(PEXLATEOBJ pxlo, ULONG iColor)
@ -72,6 +84,7 @@ EXLATEOBJ_iXlateRGBtoBGR(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateRGBto555(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlateRGBto555(PEXLATEOBJ pxlo, ULONG iColor)
@ -93,6 +106,7 @@ EXLATEOBJ_iXlateRGBto555(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateBGRto555(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlateBGRto555(PEXLATEOBJ pxlo, ULONG iColor)
@ -114,6 +128,7 @@ EXLATEOBJ_iXlateBGRto555(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateRGBto565(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlateRGBto565(PEXLATEOBJ pxlo, ULONG iColor)
@ -135,6 +150,7 @@ EXLATEOBJ_iXlateRGBto565(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateBGRto565(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlateBGRto565(PEXLATEOBJ pxlo, ULONG iColor)
@ -156,6 +172,7 @@ EXLATEOBJ_iXlateBGRto565(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateRGBtoPal(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateRGBtoPal(PEXLATEOBJ pexlo, ULONG iColor)
@ -163,6 +180,7 @@ EXLATEOBJ_iXlateRGBtoPal(PEXLATEOBJ pexlo, ULONG iColor)
return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor); return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor);
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate555toRGB(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlate555toRGB(PEXLATEOBJ pxlo, ULONG iColor)
@ -183,6 +201,7 @@ EXLATEOBJ_iXlate555toRGB(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate555toBGR(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlate555toBGR(PEXLATEOBJ pxlo, ULONG iColor)
@ -203,6 +222,7 @@ EXLATEOBJ_iXlate555toBGR(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate555to565(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlate555to565(PEXLATEOBJ pxlo, ULONG iColor)
@ -223,6 +243,7 @@ EXLATEOBJ_iXlate555to565(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate555toPal(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlate555toPal(PEXLATEOBJ pexlo, ULONG iColor)
@ -232,6 +253,7 @@ EXLATEOBJ_iXlate555toPal(PEXLATEOBJ pexlo, ULONG iColor)
return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor); return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor);
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate565to555(PEXLATEOBJ pxlo, ULONG iColor) EXLATEOBJ_iXlate565to555(PEXLATEOBJ pxlo, ULONG iColor)
@ -248,6 +270,7 @@ EXLATEOBJ_iXlate565to555(PEXLATEOBJ pxlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate565toRGB(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlate565toRGB(PEXLATEOBJ pexlo, ULONG iColor)
@ -268,6 +291,7 @@ EXLATEOBJ_iXlate565toRGB(PEXLATEOBJ pexlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate565toBGR(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlate565toBGR(PEXLATEOBJ pexlo, ULONG iColor)
@ -288,6 +312,7 @@ EXLATEOBJ_iXlate565toBGR(PEXLATEOBJ pexlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlate565toPal(EXLATEOBJ *pexlo, ULONG iColor) EXLATEOBJ_iXlate565toPal(EXLATEOBJ *pexlo, ULONG iColor)
@ -297,6 +322,7 @@ EXLATEOBJ_iXlate565toPal(EXLATEOBJ *pexlo, ULONG iColor)
return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor); return PALETTE_ulGetNearestPaletteIndex(pexlo->ppalDst, iColor);
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateShiftAndMask(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateShiftAndMask(PEXLATEOBJ pexlo, ULONG iColor)
@ -310,6 +336,7 @@ EXLATEOBJ_iXlateShiftAndMask(PEXLATEOBJ pexlo, ULONG iColor)
return iNewColor; return iNewColor;
} }
_Function_class_(FN_XLATE)
ULONG ULONG
FASTCALL FASTCALL
EXLATEOBJ_iXlateBitfieldsToPal(PEXLATEOBJ pexlo, ULONG iColor) EXLATEOBJ_iXlateBitfieldsToPal(PEXLATEOBJ pexlo, ULONG iColor)

View file

@ -11,7 +11,7 @@ struct _EXLATEOBJ;
_Function_class_(FN_XLATE) _Function_class_(FN_XLATE)
typedef typedef
ULONG ULONG
(FASTCALL *PFN_XLATE)( (FASTCALL *PFN_XLATE)(
_In_ struct _EXLATEOBJ *pexlo, _In_ struct _EXLATEOBJ *pexlo,
_In_ ULONG iColor); _In_ ULONG iColor);
@ -84,10 +84,3 @@ NTAPI
EXLATEOBJ_vCleanup( EXLATEOBJ_vCleanup(
_Inout_ PEXLATEOBJ pexlo); _Inout_ PEXLATEOBJ pexlo);
_Always_(_Post_satisfies_(return==iColor))
ULONG
FASTCALL
EXLATEOBJ_iXlateTrivial(
_In_ PEXLATEOBJ pexlo,
_In_ ULONG iColor);

View file

@ -555,6 +555,11 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
pDC->prgnRao = IntSysCreateRectpRgn(0,0,0,0); pDC->prgnRao = IntSysCreateRectpRgn(0,0,0,0);
} }
if (!pDC->prgnRao)
{
return ERROR;
}
if (pDC->dclevel.prgnMeta && pDC->dclevel.prgnClip) if (pDC->dclevel.prgnMeta && pDC->dclevel.prgnClip)
{ {
IntGdiCombineRgn( pDC->prgnAPI, IntGdiCombineRgn( pDC->prgnAPI,
@ -585,7 +590,6 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
pDC->prgnAPI, pDC->prgnAPI,
RGN_AND); RGN_AND);
// FIXME: pDC->prgnRao may be NULL
RtlCopyMemory(&pDC->erclClip, RtlCopyMemory(&pDC->erclClip,
&pDC->prgnRao->rdh.rcBound, &pDC->prgnRao->rdh.rcBound,
sizeof(RECTL)); sizeof(RECTL));
@ -599,8 +603,8 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
// With pDC->co.pClipRgn->Buffer, // With pDC->co.pClipRgn->Buffer,
// pDC->co.pClipRgn = pDC->prgnRao ? pDC->prgnRao : pDC->prgnVis; // pDC->co.pClipRgn = pDC->prgnRao ? pDC->prgnRao : pDC->prgnVis;
co = IntEngCreateClipRegion( ((PROSRGNDATA)pDC->prgnRao)->rdh.nCount, co = IntEngCreateClipRegion(pDC->prgnRao->rdh.nCount,
((PROSRGNDATA)pDC->prgnRao)->Buffer, pDC->prgnRao->Buffer,
&pDC->erclClip); &pDC->erclClip);
if (co) if (co)
{ {

View file

@ -430,6 +430,7 @@ NtGdiTransformPoints(
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
/* Do not set last error */ /* Do not set last error */
ret = 0;
} }
_SEH2_END; _SEH2_END;
@ -1232,7 +1233,6 @@ NtGdiGetDCPoint(
POINTL SafePoint; POINTL SafePoint;
SIZE Size; SIZE Size;
PSIZEL pszlViewportExt; PSIZEL pszlViewportExt;
NTSTATUS Status = STATUS_SUCCESS;
if (!Point) if (!Point)
{ {
@ -1293,15 +1293,9 @@ NtGdiGetDCPoint(
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
if (!NT_SUCCESS(Status))
{
SetLastNtError(Status);
Ret = FALSE; Ret = FALSE;
} }
_SEH2_END;
} }
DC_UnlockDc(pdc); DC_UnlockDc(pdc);

View file

@ -867,7 +867,7 @@ GreGetDIBitsInternal(
} }
psurfDest = SURFACE_ShareLockSurface(hBmpDest); psurfDest = SURFACE_ShareLockSurface(hBmpDest);
RECTL_vSetRect(&rcDest, 0, 0, ScanLines, psurf->SurfObj.sizlBitmap.cx); RECTL_vSetRect(&rcDest, 0, 0, ScanLines, psurf->SurfObj.sizlBitmap.cx);
srcPoint.x = 0; srcPoint.x = 0;
@ -1014,7 +1014,7 @@ NtGdiGetDIBitsInternal(
_SEH2_TRY _SEH2_TRY
{ {
/* Copy the data back */ /* Copy the data back */
ProbeForWrite(pbmiUser, cjMaxInfo, 1); ProbeForWrite(pbmiUser, cjMaxInfo, 1);
RtlCopyMemory(pbmiUser, pbmi, cjMaxInfo); RtlCopyMemory(pbmiUser, pbmi, cjMaxInfo);
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
@ -1646,7 +1646,7 @@ cleanup:
GreDeleteObject(res); GreDeleteObject(res);
res = 0; res = 0;
} }
if(ppalDIB) if(ppalDIB)
{ {
PALETTE_ShareUnlockPalette(ppalDIB); PALETTE_ShareUnlockPalette(ppalDIB);
@ -1862,23 +1862,23 @@ DIB_FreeConvertedBitmapInfo(BITMAPINFO* converted, BITMAPINFO* orig, DWORD usage
BITMAPCOREINFO* pbmci; BITMAPCOREINFO* pbmci;
if(converted == orig) if(converted == orig)
return; return;
if(usage == -1) if(usage == -1)
{ {
/* Caller don't want any conversion */ /* Caller don't want any conversion */
ExFreePoolWithTag(converted, TAG_DIB); ExFreePoolWithTag(converted, TAG_DIB);
return; return;
} }
/* Perform inverse conversion */ /* Perform inverse conversion */
pbmci = (BITMAPCOREINFO*)orig; pbmci = (BITMAPCOREINFO*)orig;
ASSERT(pbmci->bmciHeader.bcSize == sizeof(BITMAPCOREHEADER)); ASSERT(pbmci->bmciHeader.bcSize == sizeof(BITMAPCOREHEADER));
pbmci->bmciHeader.bcBitCount = converted->bmiHeader.biBitCount; pbmci->bmciHeader.bcBitCount = converted->bmiHeader.biBitCount;
pbmci->bmciHeader.bcWidth = converted->bmiHeader.biWidth; pbmci->bmciHeader.bcWidth = converted->bmiHeader.biWidth;
pbmci->bmciHeader.bcHeight = converted->bmiHeader.biHeight; pbmci->bmciHeader.bcHeight = converted->bmiHeader.biHeight;
pbmci->bmciHeader.bcPlanes = converted->bmiHeader.biPlanes; pbmci->bmciHeader.bcPlanes = converted->bmiHeader.biPlanes;
if(pbmci->bmciHeader.bcBitCount <= 8) if(pbmci->bmciHeader.bcBitCount <= 8)
{ {
UINT numColors = converted->bmiHeader.biClrUsed; UINT numColors = converted->bmiHeader.biClrUsed;

View file

@ -3988,51 +3988,59 @@ NtGdiUnionRectWithRgn(
* *
* If the function fails, the return value is zero." * If the function fails, the return value is zero."
*/ */
DWORD APIENTRY _Success_(return!=0)
ULONG
APIENTRY
NtGdiGetRegionData( NtGdiGetRegionData(
HRGN hrgn, _In_ HRGN hrgn,
DWORD count, _In_ ULONG cjBuffer,
LPRGNDATA rgndata _Out_opt_bytecap_(cjBuffer) LPRGNDATA lpRgnData)
)
{ {
DWORD size; ULONG cjSize;
PROSRGNDATA obj = RGNOBJAPI_Lock(hrgn, NULL); PREGION prgn;
NTSTATUS Status = STATUS_SUCCESS;
if (!obj) /* Lock the region */
return 0; prgn = RGNOBJAPI_Lock(hrgn, NULL);
if (!prgn)
size = obj->rdh.nCount * sizeof(RECT);
if (count < (size + sizeof(RGNDATAHEADER)) || rgndata == NULL)
{ {
RGNOBJAPI_Unlock(obj); EngSetLastError(ERROR_INVALID_HANDLE);
if (rgndata) /* Buffer is too small, signal it by return 0 */
return 0;
else /* User requested buffer size with rgndata NULL */
return size + sizeof(RGNDATAHEADER);
}
_SEH2_TRY
{
ProbeForWrite(rgndata, count, 1);
RtlCopyMemory(rgndata, &obj->rdh, sizeof(RGNDATAHEADER));
RtlCopyMemory(rgndata->Buffer, obj->Buffer, size);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
if (!NT_SUCCESS(Status))
{
SetLastNtError(Status);
RGNOBJAPI_Unlock(obj);
return 0; return 0;
} }
RGNOBJAPI_Unlock(obj); /* Calculate the region size */
return size + sizeof(RGNDATAHEADER); cjSize = prgn->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER);
/* Check if region data is requested */
if (lpRgnData)
{
/* Check if the buffer is large enough */
if (cjBuffer >= cjSize)
{
/* Probe the buffer and copy the data */
_SEH2_TRY
{
ProbeForWrite(lpRgnData, cjSize, sizeof(ULONG));
RtlCopyMemory(lpRgnData, &prgn->rdh, sizeof(RGNDATAHEADER));
RtlCopyMemory(lpRgnData->Buffer, prgn->Buffer, cjSize);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
EngSetLastError(ERROR_INVALID_PARAMETER);
cjSize = 0;
}
_SEH2_END;
}
else
{
/* Buffer is too small */
EngSetLastError(ERROR_INVALID_PARAMETER);
cjSize = 0;
}
}
/* Unlock the region and return the size */
RGNOBJAPI_Unlock(prgn);
return cjSize;
} }
/* EOF */ /* EOF */

View file

@ -2024,13 +2024,14 @@ NtUserGetGUIThreadInfo(
DWORD idThread, DWORD idThread,
LPGUITHREADINFO lpgui); LPGUITHREADINFO lpgui);
_Success_(return!=FALSE)
BOOL BOOL
NTAPI NTAPI
NtUserGetIconInfo( NtUserGetIconInfo(
_In_ HANDLE hCurIcon, _In_ HANDLE hCurIcon,
_Out_opt_ PICONINFO IconInfo, _Out_opt_ PICONINFO IconInfo,
_Out_opt_ PUNICODE_STRING lpInstName, _Inout_opt_ PUNICODE_STRING lpInstName,
_Out_opt_ PUNICODE_STRING lpResName, _Inout_opt_ PUNICODE_STRING lpResName,
_Out_opt_ LPDWORD pbpp, _Out_opt_ LPDWORD pbpp,
_In_ BOOL bInternal); _In_ BOOL bInternal);
@ -2782,7 +2783,7 @@ typedef struct _tagFINDEXISTINGCURICONPARAM
LONG cx; LONG cx;
LONG cy; LONG cy;
} FINDEXISTINGCURICONPARAM; } FINDEXISTINGCURICONPARAM;
HICON HICON
NTAPI NTAPI
NtUserFindExistingCursorIcon( NtUserFindExistingCursorIcon(
@ -2799,7 +2800,7 @@ NtUserSetCursorIconData(
HMODULE hModule, HMODULE hModule,
HRSRC hRsrc, HRSRC hRsrc,
HRSRC hGroupRsrc); HRSRC hGroupRsrc);
HICON HICON
NTAPI NTAPI
NtUserFindExistingCursorIcon( NtUserFindExistingCursorIcon(

View file

@ -125,7 +125,7 @@ _Must_inspect_result_
NTSTATUS NTSTATUS
NTAPI NTAPI
ProbeAndCaptureUnicodeStringOrAtom( ProbeAndCaptureUnicodeStringOrAtom(
_Out_ PUNICODE_STRING pustrOut, _Out_ _When_(return>=0, _At_(pustrOut->Buffer, _Post_ _Notnull_)) PUNICODE_STRING pustrOut,
__in_data_source(USER_MODE) _In_ PUNICODE_STRING pustrUnsafe) __in_data_source(USER_MODE) _In_ PUNICODE_STRING pustrUnsafe)
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;

View file

@ -63,7 +63,7 @@ _Must_inspect_result_
NTSTATUS NTSTATUS
NTAPI NTAPI
ProbeAndCaptureUnicodeStringOrAtom( ProbeAndCaptureUnicodeStringOrAtom(
_Out_ PUNICODE_STRING pustrOut, _Out_ _When_(return>=0, _At_(pustrOut->Buffer, _Post_ _Notnull_)) PUNICODE_STRING pustrOut,
__in_data_source(USER_MODE) _In_ PUNICODE_STRING pustrUnsafe); __in_data_source(USER_MODE) _In_ PUNICODE_STRING pustrUnsafe);
/* EOF */ /* EOF */

View file

@ -240,7 +240,7 @@ IntDestroyCurIconObject(PCURICON_OBJECT CurIcon, PPROCESSINFO ppi)
HBITMAP bmpMask, bmpColor; HBITMAP bmpMask, bmpColor;
BOOLEAN Ret, bListEmpty, bFound = FALSE; BOOLEAN Ret, bListEmpty, bFound = FALSE;
PCURICON_PROCESS Current = NULL; PCURICON_PROCESS Current = NULL;
/* For handles created without any data (error handling) */ /* For handles created without any data (error handling) */
if(IsListEmpty(&CurIcon->ProcessList)) if(IsListEmpty(&CurIcon->ProcessList))
goto emptyList; goto emptyList;
@ -256,7 +256,7 @@ IntDestroyCurIconObject(PCURICON_OBJECT CurIcon, PPROCESSINFO ppi)
break; break;
} }
} }
if(!bFound) if(!bFound)
{ {
/* This object doesn't belong to this process */ /* This object doesn't belong to this process */
@ -386,6 +386,18 @@ NtUserGetIconInfo(
ProbeForWrite(IconInfo, sizeof(ICONINFO), 1); ProbeForWrite(IconInfo, sizeof(ICONINFO), 1);
RtlCopyMemory(IconInfo, &ii, sizeof(ICONINFO)); RtlCopyMemory(IconInfo, &ii, sizeof(ICONINFO));
/// @todo Implement support for lpInstName
if (lpInstName)
{
RtlInitEmptyUnicodeString(lpInstName, NULL, 0);
}
/// @todo Implement support for lpResName
if (lpResName)
{
RtlInitEmptyUnicodeString(lpResName, NULL, 0);
}
if (pbpp) if (pbpp)
{ {
ProbeForWrite(pbpp, sizeof(DWORD), 1); ProbeForWrite(pbpp, sizeof(DWORD), 1);
@ -1049,7 +1061,7 @@ UserDrawIconEx(
RECTL rcDest, rcSrc; RECTL rcDest, rcSrc;
CLIPOBJ* pdcClipObj = NULL; CLIPOBJ* pdcClipObj = NULL;
EXLATEOBJ exlo; EXLATEOBJ exlo;
/* Stupid case */ /* Stupid case */
if((diFlags & DI_NORMAL) == 0) if((diFlags & DI_NORMAL) == 0)
{ {
@ -1059,12 +1071,12 @@ UserDrawIconEx(
hbmMask = pIcon->IconInfo.hbmMask; hbmMask = pIcon->IconInfo.hbmMask;
hbmColor = pIcon->IconInfo.hbmColor; hbmColor = pIcon->IconInfo.hbmColor;
if (istepIfAniCur) if (istepIfAniCur)
ERR("NtUserDrawIconEx: istepIfAniCur is not supported!\n"); ERR("NtUserDrawIconEx: istepIfAniCur is not supported!\n");
/* /*
* Get our objects. * Get our objects.
* Shared locks are enough, we are only reading those bitmaps * Shared locks are enough, we are only reading those bitmaps
*/ */
psurfMask = SURFACE_ShareLockSurface(hbmMask); psurfMask = SURFACE_ShareLockSurface(hbmMask);
@ -1073,7 +1085,7 @@ UserDrawIconEx(
ERR("Unable to lock the mask surface.\n"); ERR("Unable to lock the mask surface.\n");
return FALSE; return FALSE;
} }
/* Color bitmap is not mandatory */ /* Color bitmap is not mandatory */
if(hbmColor == NULL) if(hbmColor == NULL)
{ {
@ -1087,7 +1099,7 @@ UserDrawIconEx(
SURFACE_ShareUnlockSurface(psurfMask); SURFACE_ShareUnlockSurface(psurfMask);
return FALSE; return FALSE;
} }
/* Set source rect */ /* Set source rect */
RECTL_vSetRect(&rcSrc, 0, 0, pIcon->Size.cx, pIcon->Size.cy); RECTL_vSetRect(&rcSrc, 0, 0, pIcon->Size.cx, pIcon->Size.cy);
@ -1119,17 +1131,17 @@ UserDrawIconEx(
if (!cxWidth) if (!cxWidth)
{ {
if(diFlags & DI_DEFAULTSIZE) if(diFlags & DI_DEFAULTSIZE)
cxWidth = pIcon->IconInfo.fIcon ? cxWidth = pIcon->IconInfo.fIcon ?
UserGetSystemMetrics(SM_CXICON) : UserGetSystemMetrics(SM_CXCURSOR); UserGetSystemMetrics(SM_CXICON) : UserGetSystemMetrics(SM_CXCURSOR);
else else
cxWidth = pIcon->Size.cx; cxWidth = pIcon->Size.cx;
} }
/* Fix height parameter, if needed */ /* Fix height parameter, if needed */
if (!cyHeight) if (!cyHeight)
{ {
if(diFlags & DI_DEFAULTSIZE) if(diFlags & DI_DEFAULTSIZE)
cyHeight = pIcon->IconInfo.fIcon ? cyHeight = pIcon->IconInfo.fIcon ?
UserGetSystemMetrics(SM_CYICON) : UserGetSystemMetrics(SM_CYCURSOR); UserGetSystemMetrics(SM_CYICON) : UserGetSystemMetrics(SM_CYCURSOR);
else else
cyHeight = pIcon->Size.cy; cyHeight = pIcon->Size.cy;
@ -1143,9 +1155,9 @@ UserDrawIconEx(
/* Yes: Allocate and paint the offscreen surface */ /* Yes: Allocate and paint the offscreen surface */
EBRUSHOBJ eboFill; EBRUSHOBJ eboFill;
PBRUSH pbrush = BRUSH_ShareLockBrush(hbrFlickerFreeDraw); PBRUSH pbrush = BRUSH_ShareLockBrush(hbrFlickerFreeDraw);
TRACE("Performing off-screen rendering.\n"); TRACE("Performing off-screen rendering.\n");
if(!pbrush) if(!pbrush)
{ {
ERR("Failed to get brush object.\n"); ERR("Failed to get brush object.\n");
@ -1171,11 +1183,11 @@ UserDrawIconEx(
BRUSH_ShareUnlockBrush(pbrush); BRUSH_ShareUnlockBrush(pbrush);
return FALSE; return FALSE;
} }
/* Paint the brush */ /* Paint the brush */
EBRUSHOBJ_vInit(&eboFill, pbrush, psurfOffScreen, 0x00FFFFFF, 0, NULL); EBRUSHOBJ_vInit(&eboFill, pbrush, psurfOffScreen, 0x00FFFFFF, 0, NULL);
RECTL_vSetRect(&rcDest, 0, 0, cxWidth, cyHeight); RECTL_vSetRect(&rcDest, 0, 0, cxWidth, cyHeight);
Ret = IntEngBitBlt(&psurfOffScreen->SurfObj, Ret = IntEngBitBlt(&psurfOffScreen->SurfObj,
NULL, NULL,
NULL, NULL,
@ -1191,7 +1203,7 @@ UserDrawIconEx(
/* Clean up everything */ /* Clean up everything */
EBRUSHOBJ_vCleanup(&eboFill); EBRUSHOBJ_vCleanup(&eboFill);
BRUSH_ShareUnlockBrush(pbrush); BRUSH_ShareUnlockBrush(pbrush);
if(!Ret) if(!Ret)
{ {
ERR("Failed to paint the off-screen surface.\n"); ERR("Failed to paint the off-screen surface.\n");
@ -1200,7 +1212,7 @@ UserDrawIconEx(
GDIOBJ_vDeleteObject(&psurfOffScreen->BaseObject); GDIOBJ_vDeleteObject(&psurfOffScreen->BaseObject);
return FALSE; return FALSE;
} }
/* We now have our destination surface */ /* We now have our destination surface */
psurfDest = psurfOffScreen; psurfDest = psurfOffScreen;
} }
@ -1208,7 +1220,7 @@ UserDrawIconEx(
{ {
/* We directly draw to the DC */ /* We directly draw to the DC */
TRACE("Performing on screen rendering.\n"); TRACE("Performing on screen rendering.\n");
psurfOffScreen = NULL; psurfOffScreen = NULL;
pdc = DC_LockDc(hDc); pdc = DC_LockDc(hDc);
if(!pdc) if(!pdc)
@ -1222,16 +1234,16 @@ UserDrawIconEx(
RECTL_vSetRect(&rcDest, xLeft, yTop, xLeft + cxWidth, yTop + cyHeight); RECTL_vSetRect(&rcDest, xLeft, yTop, xLeft + cxWidth, yTop + cyHeight);
IntLPtoDP(pdc, (LPPOINT)&rcDest, 2); IntLPtoDP(pdc, (LPPOINT)&rcDest, 2);
RECTL_vOffsetRect(&rcDest, pdc->ptlDCOrig.x, pdc->ptlDCOrig.y); RECTL_vOffsetRect(&rcDest, pdc->ptlDCOrig.x, pdc->ptlDCOrig.y);
/* Prepare the underlying surface */ /* Prepare the underlying surface */
DC_vPrepareDCsForBlit(pdc, rcDest, NULL, rcDest); DC_vPrepareDCsForBlit(pdc, rcDest, NULL, rcDest);
/* Get the clip object */ /* Get the clip object */
pdcClipObj = pdc->rosdc.CombinedClip; pdcClipObj = pdc->rosdc.CombinedClip;
/* We now have our destination surface and rectangle */ /* We now have our destination surface and rectangle */
psurfDest = pdc->dclevel.pSurface; psurfDest = pdc->dclevel.pSurface;
if(psurfDest == NULL) if(psurfDest == NULL)
{ {
/* Empty DC */ /* Empty DC */
@ -1281,10 +1293,10 @@ UserDrawIconEx(
ptr += 4; ptr += 4;
} }
} }
/* Initialize color translation object */ /* Initialize color translation object */
EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0xFFFFFFFF, 0xFFFFFFFF, 0); EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0xFFFFFFFF, 0xFFFFFFFF, 0);
/* Now do it */ /* Now do it */
Ret = IntEngAlphaBlend(&psurfDest->SurfObj, Ret = IntEngAlphaBlend(&psurfDest->SurfObj,
&psurf->SurfObj, &psurf->SurfObj,
@ -1293,9 +1305,9 @@ UserDrawIconEx(
&rcDest, &rcDest,
&rcSrc, &rcSrc,
&blendobj); &blendobj);
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
CleanupAlpha: CleanupAlpha:
if(psurf) SURFACE_ShareUnlockSurface(psurf); if(psurf) SURFACE_ShareUnlockSurface(psurf);
if(hsurfCopy) NtGdiDeleteObjectApp(hsurfCopy); if(hsurfCopy) NtGdiDeleteObjectApp(hsurfCopy);
@ -1306,9 +1318,9 @@ UserDrawIconEx(
if (diFlags & DI_MASK) if (diFlags & DI_MASK)
{ {
DWORD rop4 = (diFlags & DI_IMAGE) ? ROP4_SRCAND : ROP4_SRCCOPY; DWORD rop4 = (diFlags & DI_IMAGE) ? ROP4_SRCAND : ROP4_SRCCOPY;
EXLATEOBJ_vInitSrcMonoXlate(&exlo, psurfDest->ppal, 0x00FFFFFF, 0); EXLATEOBJ_vInitSrcMonoXlate(&exlo, psurfDest->ppal, 0x00FFFFFF, 0);
Ret = IntEngStretchBlt(&psurfDest->SurfObj, Ret = IntEngStretchBlt(&psurfDest->SurfObj,
&psurfMask->SurfObj, &psurfMask->SurfObj,
NULL, NULL,
@ -1321,7 +1333,7 @@ UserDrawIconEx(
NULL, NULL,
NULL, NULL,
rop4); rop4);
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
if(!Ret) if(!Ret)
@ -1336,9 +1348,9 @@ UserDrawIconEx(
if (psurfColor) if (psurfColor)
{ {
DWORD rop4 = (diFlags & DI_MASK) ? ROP4_SRCINVERT : ROP4_SRCCOPY ; DWORD rop4 = (diFlags & DI_MASK) ? ROP4_SRCINVERT : ROP4_SRCCOPY ;
EXLATEOBJ_vInitialize(&exlo, psurfColor->ppal, psurfDest->ppal, 0x00FFFFFF, 0x00FFFFFF, 0); EXLATEOBJ_vInitialize(&exlo, psurfColor->ppal, psurfDest->ppal, 0x00FFFFFF, 0x00FFFFFF, 0);
Ret = IntEngStretchBlt(&psurfDest->SurfObj, Ret = IntEngStretchBlt(&psurfDest->SurfObj,
&psurfColor->SurfObj, &psurfColor->SurfObj,
NULL, NULL,
@ -1351,7 +1363,7 @@ UserDrawIconEx(
NULL, NULL,
NULL, NULL,
rop4); rop4);
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
if(!Ret) if(!Ret)
@ -1365,9 +1377,9 @@ UserDrawIconEx(
/* Mask bitmap holds the information in its bottom half */ /* Mask bitmap holds the information in its bottom half */
DWORD rop4 = (diFlags & DI_MASK) ? ROP4_SRCINVERT : ROP4_SRCCOPY; DWORD rop4 = (diFlags & DI_MASK) ? ROP4_SRCINVERT : ROP4_SRCCOPY;
RECTL_vOffsetRect(&rcSrc, 0, pIcon->Size.cy); RECTL_vOffsetRect(&rcSrc, 0, pIcon->Size.cy);
EXLATEOBJ_vInitSrcMonoXlate(&exlo, psurfDest->ppal, 0x00FFFFFF, 0); EXLATEOBJ_vInitSrcMonoXlate(&exlo, psurfDest->ppal, 0x00FFFFFF, 0);
Ret = IntEngStretchBlt(&psurfDest->SurfObj, Ret = IntEngStretchBlt(&psurfDest->SurfObj,
&psurfMask->SurfObj, &psurfMask->SurfObj,
NULL, NULL,
@ -1380,7 +1392,7 @@ UserDrawIconEx(
NULL, NULL,
NULL, NULL,
rop4); rop4);
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
if(!Ret) if(!Ret)
@ -1407,13 +1419,13 @@ done:
RECTL_vSetRect(&rcDest, xLeft, yTop, xLeft + cxWidth, yTop + cyHeight); RECTL_vSetRect(&rcDest, xLeft, yTop, xLeft + cxWidth, yTop + cyHeight);
IntLPtoDP(pdc, (LPPOINT)&rcDest, 2); IntLPtoDP(pdc, (LPPOINT)&rcDest, 2);
RECTL_vOffsetRect(&rcDest, pdc->ptlDCOrig.x, pdc->ptlDCOrig.y); RECTL_vOffsetRect(&rcDest, pdc->ptlDCOrig.x, pdc->ptlDCOrig.y);
/* Prepare the underlying surface */ /* Prepare the underlying surface */
DC_vPrepareDCsForBlit(pdc, rcDest, NULL, rcDest); DC_vPrepareDCsForBlit(pdc, rcDest, NULL, rcDest);
/* Get the clip object */ /* Get the clip object */
pdcClipObj = pdc->rosdc.CombinedClip; pdcClipObj = pdc->rosdc.CombinedClip;
/* We now have our destination surface and rectangle */ /* We now have our destination surface and rectangle */
psurfDest = pdc->dclevel.pSurface; psurfDest = pdc->dclevel.pSurface;
if(!psurfDest) if(!psurfDest)
@ -1422,10 +1434,10 @@ done:
DC_UnlockDc(pdc); DC_UnlockDc(pdc);
goto Cleanup2; goto Cleanup2;
} }
/* Color translation */ /* Color translation */
EXLATEOBJ_vInitialize(&exlo, psurfOffScreen->ppal, psurfDest->ppal, 0x00FFFFFF, 0x00FFFFFF, 0); EXLATEOBJ_vInitialize(&exlo, psurfOffScreen->ppal, psurfDest->ppal, 0x00FFFFFF, 0x00FFFFFF, 0);
/* Blt it! */ /* Blt it! */
Ret = IntEngBitBlt(&psurfDest->SurfObj, Ret = IntEngBitBlt(&psurfDest->SurfObj,
&psurfOffScreen->SurfObj, &psurfOffScreen->SurfObj,
@ -1438,7 +1450,7 @@ done:
NULL, NULL,
NULL, NULL,
ROP4_SRCCOPY); ROP4_SRCCOPY);
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
} }
Cleanup: Cleanup:
@ -1447,12 +1459,12 @@ Cleanup:
DC_vFinishBlit(pdc, NULL); DC_vFinishBlit(pdc, NULL);
DC_UnlockDc(pdc); DC_UnlockDc(pdc);
} }
Cleanup2: Cleanup2:
/* Delete off screen rendering surface */ /* Delete off screen rendering surface */
if(psurfOffScreen) if(psurfOffScreen)
GDIOBJ_vDeleteObject(&psurfOffScreen->BaseObject); GDIOBJ_vDeleteObject(&psurfOffScreen->BaseObject);
/* Unlock other surfaces */ /* Unlock other surfaces */
SURFACE_ShareUnlockSurface(psurfMask); SURFACE_ShareUnlockSurface(psurfMask);
if(psurfColor) SURFACE_ShareUnlockSurface(psurfColor); if(psurfColor) SURFACE_ShareUnlockSurface(psurfColor);

View file

@ -65,7 +65,9 @@ IntDesktopObjectParse(IN PVOID ParseObject,
/* Get the current desktop */ /* Get the current desktop */
Desktop = CONTAINING_RECORD(NextEntry, DESKTOP, ListEntry); Desktop = CONTAINING_RECORD(NextEntry, DESKTOP, ListEntry);
/// @todo Don't mess around with the object headers!
/* Get its name */ /* Get its name */
_PRAGMA_WARNING_SUPPRESS(__WARNING_DEREF_NULL_PTR)
DesktopName = GET_DESKTOP_NAME(Desktop); DesktopName = GET_DESKTOP_NAME(Desktop);
if (DesktopName) if (DesktopName)
{ {
@ -1262,7 +1264,7 @@ NtUserCreateDesktop(
dwDesiredAccess, dwDesiredAccess,
(PVOID)&Context, (PVOID)&Context,
(HANDLE*)&hdesk); (HANDLE*)&hdesk);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ERR("ObOpenObjectByName failed to open/create desktop\n"); ERR("ObOpenObjectByName failed to open/create desktop\n");
SetLastNtError(Status); SetLastNtError(Status);
@ -1294,7 +1296,7 @@ NtUserCreateDesktop(
/* Get the desktop window class. The thread desktop does not belong to any desktop /* Get the desktop window class. The thread desktop does not belong to any desktop
* so the classes created there (including the desktop class) are allocated in the shared heap * so the classes created there (including the desktop class) are allocated in the shared heap
* It would cause problems if we used a class that belongs to the caller * It would cause problems if we used a class that belongs to the caller
*/ */
ClassName.Buffer = WC_DESKTOP; ClassName.Buffer = WC_DESKTOP;
ClassName.Length = 0; ClassName.Length = 0;
@ -1327,7 +1329,7 @@ NtUserCreateDesktop(
pdesk->DesktopWindow = pWnd->head.h; pdesk->DesktopWindow = pWnd->head.h;
pdesk->pDeskInfo->spwnd = pWnd; pdesk->pDeskInfo->spwnd = pWnd;
pWnd->fnid = FNID_DESKTOP; pWnd->fnid = FNID_DESKTOP;
ClassName.Buffer = MAKEINTATOM(gpsi->atomSysClass[ICLS_HWNDMESSAGE]); ClassName.Buffer = MAKEINTATOM(gpsi->atomSysClass[ICLS_HWNDMESSAGE]);
ClassName.Length = 0; ClassName.Length = 0;
pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE); pcls = IntGetAndReferenceClass(&ClassName, 0, TRUE);

View file

@ -358,15 +358,20 @@ CanForceFG(PPROCESSINFO ppi)
*/ */
static BOOL FASTCALL static BOOL FASTCALL
co_IntSetForegroundAndFocusWindow(PWND Wnd, BOOL MouseActivate) co_IntSetForegroundAndFocusWindow(
_In_ PWND Wnd,
_In_ BOOL MouseActivate)
{ {
HWND hWnd = UserHMGetHandle(Wnd); HWND hWnd;
HWND hWndPrev = NULL; HWND hWndPrev = NULL;
PUSER_MESSAGE_QUEUE PrevForegroundQueue; PUSER_MESSAGE_QUEUE PrevForegroundQueue;
PTHREADINFO pti; PTHREADINFO pti;
BOOL fgRet = FALSE, Ret = FALSE; BOOL fgRet = FALSE, Ret = FALSE;
ASSERT_REFS_CO(Wnd); ASSERT_REFS_CO(Wnd);
NT_ASSERT(Wnd != NULL);
hWnd = UserHMGetHandle(Wnd);
TRACE("SetForegroundAndFocusWindow(%x, %s)\n", hWnd, (MouseActivate ? "TRUE" : "FALSE")); TRACE("SetForegroundAndFocusWindow(%x, %s)\n", hWnd, (MouseActivate ? "TRUE" : "FALSE"));

View file

@ -1050,6 +1050,8 @@ IntRemoveHook(PHOOK Hook)
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
/* Do nothing */
(void)0;
} }
_SEH2_END; _SEH2_END;
} }
@ -1241,6 +1243,8 @@ co_HOOK_CallHooks( INT HookId,
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
/* Do nothing */
(void)0;
} }
_SEH2_END; _SEH2_END;
} }

View file

@ -254,9 +254,10 @@ UserLoadKbdLayout(PUNICODE_STRING pwszKLID, HKL hKL)
*/ */
static static
VOID VOID
UnloadKbdFile(PKBDFILE pkf) UnloadKbdFile(_In_ PKBDFILE pkf)
{ {
PKBDFILE *ppkfLink = &gpkfList; PKBDFILE *ppkfLink = &gpkfList;
NT_ASSERT(pkf != NULL);
/* Find previous object */ /* Find previous object */
while (*ppkfLink) while (*ppkfLink)

View file

@ -385,7 +385,7 @@ IntTranslateChar(WORD wVirtKey,
/* If nothing has been found in layout, check if this is ASCII control character. /* If nothing has been found in layout, check if this is ASCII control character.
Note: we could add it to layout table, but windows does not have it there */ Note: we could add it to layout table, but windows does not have it there */
if (wVirtKey >= 'A' && wVirtKey <= 'Z' && if (wVirtKey >= 'A' && wVirtKey <= 'Z' &&
IS_KEY_DOWN(pKeyState, VK_CONTROL) && pKeyState && IS_KEY_DOWN(pKeyState, VK_CONTROL) &&
!IS_KEY_DOWN(pKeyState, VK_MENU)) !IS_KEY_DOWN(pKeyState, VK_MENU))
{ {
*pwcTranslatedChar = (wVirtKey - 'A') + 1; /* ASCII control character */ *pwcTranslatedChar = (wVirtKey - 'A') + 1; /* ASCII control character */
@ -1097,7 +1097,7 @@ IntTranslateKbdMessage(LPMSG lpMsg,
{ {
pti->KeyboardLayout = W32kGetDefaultKeyLayout(); pti->KeyboardLayout = W32kGetDefaultKeyLayout();
pti->pClientInfo->hKL = pti->KeyboardLayout ? pti->KeyboardLayout->hkl : NULL; pti->pClientInfo->hKL = pti->KeyboardLayout ? pti->KeyboardLayout->hkl : NULL;
pKbdTbl = pti->KeyboardLayout->spkf->pKbdTbl; pKbdTbl = pti->KeyboardLayout ? pti->KeyboardLayout->spkf->pKbdTbl : NULL;
} }
else else
pKbdTbl = pti->KeyboardLayout->spkf->pKbdTbl; pKbdTbl = pti->KeyboardLayout->spkf->pKbdTbl;

View file

@ -249,8 +249,8 @@ IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
PPROCESSINFO CurrentWin32Process; PPROCESSINFO CurrentWin32Process;
Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable, Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
NULL, NULL,
NULL, NULL,
Handle, Handle,
otMenu, otMenu,
sizeof(MENU_OBJECT)); sizeof(MENU_OBJECT));
@ -361,8 +361,8 @@ IntCloneMenu(PMENU_OBJECT Source)
return NULL; return NULL;
Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable, Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
NULL, NULL,
NULL, NULL,
&hMenu, &hMenu,
otMenu, otMenu,
sizeof(MENU_OBJECT)); sizeof(MENU_OBJECT));
@ -803,13 +803,18 @@ IntSetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, PROSMENUITEMINF
} }
BOOL FASTCALL BOOL FASTCALL
IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition, IntInsertMenuItem(
PROSMENUITEMINFO ItemInfo) _In_ PMENU_OBJECT MenuObject,
UINT uItem,
BOOL fByPosition,
PROSMENUITEMINFO ItemInfo)
{ {
int pos; int pos;
PMENU_ITEM MenuItem; PMENU_ITEM MenuItem;
PMENU_OBJECT SubMenu = NULL; PMENU_OBJECT SubMenu = NULL;
NT_ASSERT(MenuObject != NULL);
if (MAX_MENU_ITEMS <= MenuObject->MenuInfo.MenuItemCount) if (MAX_MENU_ITEMS <= MenuObject->MenuInfo.MenuItemCount)
{ {
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);

View file

@ -64,7 +64,7 @@ BOOL FASTCALL
IntCleanupMenus(struct _EPROCESS *Process, PPROCESSINFO Win32Process); IntCleanupMenus(struct _EPROCESS *Process, PPROCESSINFO Win32Process);
BOOL FASTCALL BOOL FASTCALL
IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition, IntInsertMenuItem(_In_ PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition,
PROSMENUITEMINFO ItemInfo); PROSMENUITEMINFO ItemInfo);
PMENU_OBJECT FASTCALL PMENU_OBJECT FASTCALL

View file

@ -116,7 +116,7 @@ typedef struct tagMSGMEMORY
} }
MSGMEMORY, *PMSGMEMORY; MSGMEMORY, *PMSGMEMORY;
static MSGMEMORY MsgMemory[] = static MSGMEMORY g_MsgMemory[] =
{ {
{ WM_CREATE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE }, { WM_CREATE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE },
{ WM_DDE_ACK, sizeof(KMDDELPARAM), MMS_FLAG_READ }, { WM_DDE_ACK, sizeof(KMDDELPARAM), MMS_FLAG_READ },
@ -140,8 +140,8 @@ FindMsgMemory(UINT Msg)
PMSGMEMORY MsgMemoryEntry; PMSGMEMORY MsgMemoryEntry;
/* See if this message type is present in the table */ /* See if this message type is present in the table */
for (MsgMemoryEntry = MsgMemory; for (MsgMemoryEntry = g_MsgMemory;
MsgMemoryEntry < MsgMemory + sizeof(MsgMemory) / sizeof(MSGMEMORY); MsgMemoryEntry < g_MsgMemory + sizeof(g_MsgMemory) / sizeof(MSGMEMORY);
MsgMemoryEntry++) MsgMemoryEntry++)
{ {
if (Msg == MsgMemoryEntry->Message) if (Msg == MsgMemoryEntry->Message)
@ -225,9 +225,9 @@ MsgMemorySize(PMSGMEMORY MsgMemoryEntry, WPARAM wParam, LPARAM lParam)
UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam) UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam)
{ {
PMSGMEMORY MsgMemory = FindMsgMemory(Msg); PMSGMEMORY MsgMemoryEntry = FindMsgMemory(Msg);
if(MsgMemory == NULL) return 0; if(MsgMemoryEntry == NULL) return 0;
return MsgMemorySize(MsgMemory, wParam, lParam); return MsgMemorySize(MsgMemoryEntry, wParam, lParam);
} }
static NTSTATUS static NTSTATUS
@ -388,9 +388,9 @@ UnpackParam(LPARAM lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL No
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
if (MsgMemory->Flags == MMS_FLAG_READWRITE) if (MsgMemoryEntry->Flags == MMS_FLAG_READWRITE)
{ {
//RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemory->Size); //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemoryEntry->Size);
} }
ExFreePool((PVOID) lParamPacked); ExFreePool((PVOID) lParamPacked);
return STATUS_SUCCESS; return STATUS_SUCCESS;

View file

@ -139,7 +139,7 @@ UserAttachMonitor(IN HDEV hDev)
TRACE("Couldnt create monitor object\n"); TRACE("Couldnt create monitor object\n");
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }
pMonitor->hDev = hDev; pMonitor->hDev = hDev;
pMonitor->cWndStack = 0; pMonitor->cWndStack = 0;
@ -185,7 +185,7 @@ UserDetachMonitor(IN HDEV hDev)
{ {
if (pMonitor->hDev == hDev) if (pMonitor->hDev == hDev)
break; break;
pLink = &pMonitor->pMonitorNext; pLink = &pMonitor->pMonitorNext;
pMonitor = pMonitor->pMonitorNext; pMonitor = pMonitor->pMonitorNext;
} }

View file

@ -704,7 +704,7 @@ MsqDestroyMessage(PUSER_MESSAGE Message)
} }
BOOLEAN FASTCALL BOOLEAN FASTCALL
co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue) co_MsqDispatchOneSentMessage(_In_ PUSER_MESSAGE_QUEUE MessageQueue)
{ {
PUSER_SENT_MESSAGE SaveMsg, Message; PUSER_SENT_MESSAGE SaveMsg, Message;
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
@ -1331,7 +1331,7 @@ FASTCALL
IntTrackMouseMove(PWND pwndTrack, PDESKTOP pDesk, PMSG msg, USHORT hittest) IntTrackMouseMove(PWND pwndTrack, PDESKTOP pDesk, PMSG msg, USHORT hittest)
{ {
// PWND pwndTrack = IntChildrenWindowFromPoint(pwndMsg, msg->pt.x, msg->pt.y); // PWND pwndTrack = IntChildrenWindowFromPoint(pwndMsg, msg->pt.x, msg->pt.y);
hittest = GetNCHitEx(pwndTrack, msg->pt); hittest = (USHORT)GetNCHitEx(pwndTrack, msg->pt); /// @todo WTF is this???
if ( pDesk->spwndTrack != pwndTrack || // Change with tracking window or if ( pDesk->spwndTrack != pwndTrack || // Change with tracking window or
msg->message != WM_MOUSEMOVE || // Mouse click changes or msg->message != WM_MOUSEMOVE || // Mouse click changes or

View file

@ -188,7 +188,7 @@ BOOLEAN FASTCALL MsqInitializeMessageQueue(PTHREADINFO, PUSER_MESSAGE_QUEUE);
PUSER_MESSAGE_QUEUE FASTCALL MsqCreateMessageQueue(PTHREADINFO); PUSER_MESSAGE_QUEUE FASTCALL MsqCreateMessageQueue(PTHREADINFO);
VOID FASTCALL MsqDestroyMessageQueue(PTHREADINFO); VOID FASTCALL MsqDestroyMessageQueue(PTHREADINFO);
INIT_FUNCTION NTSTATUS NTAPI MsqInitializeImpl(VOID); INIT_FUNCTION NTSTATUS NTAPI MsqInitializeImpl(VOID);
BOOLEAN FASTCALL co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue); BOOLEAN FASTCALL co_MsqDispatchOneSentMessage(_In_ PUSER_MESSAGE_QUEUE MessageQueue);
NTSTATUS FASTCALL NTSTATUS FASTCALL
co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter, co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
UINT MsgFilterMin, UINT MsgFilterMax); UINT MsgFilterMin, UINT MsgFilterMax);

View file

@ -345,7 +345,7 @@ co_IntSetScrollInfo(PWND Window, INT nBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
UINT new_flags; UINT new_flags;
INT action = 0; INT action = 0;
PSBDATA pSBData; PSBDATA pSBData;
DWORD OldPos; DWORD OldPos = 0;
BOOL bChangeParams = FALSE; /* Don't show/hide scrollbar if params don't change */ BOOL bChangeParams = FALSE; /* Don't show/hide scrollbar if params don't change */
ASSERT_REFS_CO(Window); ASSERT_REFS_CO(Window);

View file

@ -617,7 +617,7 @@ SpiSetWallpaper(PVOID pvParam, FLONG fl)
} }
/* Capture UNICODE_STRING */ /* Capture UNICODE_STRING */
bResult = SpiMemCopy(&ustr, pvParam, sizeof(UNICODE_STRING), fl & SPIF_PROTECT, 0); bResult = SpiMemCopy(&ustr, pvParam, sizeof(ustr), fl & SPIF_PROTECT, 0);
if (!bResult) return 0; if (!bResult) return 0;
if (ustr.Length > MAX_PATH * sizeof(WCHAR)) if (ustr.Length > MAX_PATH * sizeof(WCHAR))
return 0; return 0;

View file

@ -141,7 +141,7 @@ typedef struct _SPIVALUES
ULONG cxWallpaper, cyWallpaper; ULONG cxWallpaper, cyWallpaper;
WALLPAPER_MODE WallpaperMode; WALLPAPER_MODE WallpaperMode;
UNICODE_STRING ustrWallpaper; UNICODE_STRING ustrWallpaper;
WCHAR awcWallpaper[MAX_PATH]; WCHAR awcWallpaper[MAX_PATH + 1];
BOOL bHandHeld; BOOL bHandHeld;
BOOL bFastTaskSwitch; BOOL bFastTaskSwitch;

View file

@ -359,7 +359,7 @@ FASTCALL
StartTheTimers(VOID) StartTheTimers(VOID)
{ {
// Need to start gdi syncro timers then start timer with Hang App proc // Need to start gdi syncro timers then start timer with Hang App proc
// that calles Idle process so the screen savers will know to run...... // that calles Idle process so the screen savers will know to run......
IntSetTimer(NULL, 0, 1000, HungAppSysTimerProc, TMRF_RIT); IntSetTimer(NULL, 0, 1000, HungAppSysTimerProc, TMRF_RIT);
// Test Timers // Test Timers
// IntSetTimer(NULL, 0, 1000, SystemTimerProc, TMRF_RIT); // IntSetTimer(NULL, 0, 1000, SystemTimerProc, TMRF_RIT);
@ -584,9 +584,14 @@ NTAPI
InitTimerImpl(VOID) InitTimerImpl(VOID)
{ {
ULONG BitmapBytes; ULONG BitmapBytes;
/* Allocate FAST_MUTEX from non paged pool */ /* Allocate FAST_MUTEX from non paged pool */
Mutex = ExAllocatePoolWithTag(NonPagedPool, sizeof(FAST_MUTEX), TAG_INTERNAL_SYNC); Mutex = ExAllocatePoolWithTag(NonPagedPool, sizeof(FAST_MUTEX), TAG_INTERNAL_SYNC);
if (!Mutex)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
ExInitializeFastMutex(Mutex); ExInitializeFastMutex(Mutex);
BitmapBytes = ROUND_UP(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8; BitmapBytes = ROUND_UP(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8;

View file

@ -852,7 +852,7 @@ DceResetActiveDCEs(PWND Window)
{ {
if (!pDCE->hwndCurrent) if (!pDCE->hwndCurrent)
CurrentWindow = NULL; CurrentWindow = NULL;
else else
CurrentWindow = UserGetWindowObject(pDCE->hwndCurrent); CurrentWindow = UserGetWindowObject(pDCE->hwndCurrent);
if (NULL == CurrentWindow) if (NULL == CurrentWindow)
{ {

View file

@ -497,6 +497,7 @@ static LRESULT co_UserFreeWindow(PWND Window,
/* flush the message queue */ /* flush the message queue */
MsqRemoveWindowMessagesFromQueue(Window); MsqRemoveWindowMessagesFromQueue(Window);
NT_ASSERT(Window->head.pti);
IntDereferenceMessageQueue(Window->head.pti->MessageQueue); IntDereferenceMessageQueue(Window->head.pti->MessageQueue);
/* from now on no messages can be sent to this window anymore */ /* from now on no messages can be sent to this window anymore */
@ -1987,7 +1988,7 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
PWINSTATION_OBJECT WinSta; PWINSTATION_OBJECT WinSta;
PCLS Class = NULL; PCLS Class = NULL;
SIZE Size; SIZE Size;
POINT MaxPos; POINT MaxSize, MaxPos, MinTrack, MaxTrack;
CBT_CREATEWNDW * pCbtCreate; CBT_CREATEWNDW * pCbtCreate;
LRESULT Result; LRESULT Result;
USER_REFERENCE_ENTRY ParentRef, Ref; USER_REFERENCE_ENTRY ParentRef, Ref;
@ -2190,8 +2191,6 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
if ((Cs->style & WS_THICKFRAME) || !(Cs->style & (WS_POPUP | WS_CHILD))) if ((Cs->style & WS_THICKFRAME) || !(Cs->style & (WS_POPUP | WS_CHILD)))
{ {
POINT MaxSize, MaxPos, MinTrack, MaxTrack;
co_WinPosGetMinMaxInfo(Window, &MaxSize, &MaxPos, &MinTrack, &MaxTrack); co_WinPosGetMinMaxInfo(Window, &MaxSize, &MaxPos, &MinTrack, &MaxTrack);
if (Size.cx > MaxTrack.x) Size.cx = MaxTrack.x; if (Size.cx > MaxTrack.x) Size.cx = MaxTrack.x;
if (Size.cy > MaxTrack.y) Size.cy = MaxTrack.y; if (Size.cy > MaxTrack.y) Size.cy = MaxTrack.y;
@ -2542,7 +2541,7 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWND Window)
TRACE("co_UserDestroyWindow \n"); TRACE("co_UserDestroyWindow \n");
/* Check for owner thread */ /* Check for owner thread */
if ( Window->head.pti != PsGetCurrentThreadWin32Thread()) if ( Window->head.pti != PsGetCurrentThreadWin32Thread())
{ {
/* Check if we are destroying the desktop window */ /* Check if we are destroying the desktop window */
@ -2627,7 +2626,7 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWND Window)
* Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
*/ */
if ((ti != NULL) & (ti->pDeskInfo != NULL)) if ((ti != NULL) && (ti->pDeskInfo != NULL))
{ {
if (ti->pDeskInfo->hShellWindow == hWnd) if (ti->pDeskInfo->hShellWindow == hWnd)
{ {
@ -3074,8 +3073,6 @@ PWND FASTCALL UserGetAncestor(PWND Wnd, UINT Type)
for (;;) for (;;)
{ {
PWND Parent;
Parent = IntGetParent(WndAncestor); Parent = IntGetParent(WndAncestor);
if (!Parent) if (!Parent)

View file

@ -57,7 +57,10 @@ UserCreateWinstaDirectoy()
Peb = NtCurrentPeb(); Peb = NtCurrentPeb();
if(Peb->SessionId == 0) if(Peb->SessionId == 0)
{ {
RtlCreateUnicodeString(&gustrWindowStationsDir, WINSTA_OBJ_DIR); if (!RtlCreateUnicodeString(&gustrWindowStationsDir, WINSTA_OBJ_DIR))
{
return STATUS_INSUFFICIENT_RESOURCES;
}
} }
else else
{ {
@ -67,7 +70,10 @@ UserCreateWinstaDirectoy()
Peb->SessionId, Peb->SessionId,
WINSTA_OBJ_DIR); WINSTA_OBJ_DIR);
RtlCreateUnicodeString( &gustrWindowStationsDir, wstrWindowStationsDir); if (!RtlCreateUnicodeString(&gustrWindowStationsDir, wstrWindowStationsDir))
{
return STATUS_INSUFFICIENT_RESOURCES;
}
} }
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
@ -1024,27 +1030,30 @@ BuildWindowStationNameList(
&ReturnLength); &ReturnLength);
if (STATUS_BUFFER_TOO_SMALL == Status) if (STATUS_BUFFER_TOO_SMALL == Status)
{ {
BufferSize = ReturnLength; ObDereferenceObject(DirectoryHandle);
Buffer = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_WINSTA); return STATUS_NO_MEMORY;
if (NULL == Buffer) }
{
ObDereferenceObject(DirectoryHandle);
return STATUS_NO_MEMORY;
}
/* We should have a sufficiently large buffer now */ BufferSize = ReturnLength;
Context = 0; Buffer = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_WINSTA);
Status = ZwQueryDirectoryObject(DirectoryHandle, Buffer, BufferSize, if (NULL == Buffer)
FALSE, TRUE, &Context, &ReturnLength); {
if (! NT_SUCCESS(Status) || ObDereferenceObject(DirectoryHandle);
STATUS_NO_MORE_ENTRIES != ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE, return STATUS_NO_MEMORY;
FALSE, &Context, NULL)) }
{
/* Something went wrong, maybe someone added a directory entry? Just give up. */ /* We should have a sufficiently large buffer now */
ExFreePoolWithTag(Buffer, TAG_WINSTA); Context = 0;
ObDereferenceObject(DirectoryHandle); Status = ZwQueryDirectoryObject(DirectoryHandle, Buffer, BufferSize,
return NT_SUCCESS(Status) ? STATUS_INTERNAL_ERROR : Status; FALSE, TRUE, &Context, &ReturnLength);
} if (! NT_SUCCESS(Status) ||
STATUS_NO_MORE_ENTRIES != ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE,
FALSE, &Context, NULL))
{
/* Something went wrong, maybe someone added a directory entry? Just give up. */
ExFreePoolWithTag(Buffer, TAG_WINSTA);
ObDereferenceObject(DirectoryHandle);
return NT_SUCCESS(Status) ? STATUS_INTERNAL_ERROR : Status;
} }
} }
@ -1130,7 +1139,7 @@ BuildWindowStationNameList(
/* /*
* Clean up * Clean up
*/ */
if (NULL != Buffer && Buffer != InitialBuffer) if (Buffer != InitialBuffer)
{ {
ExFreePoolWithTag(Buffer, TAG_WINSTA); ExFreePoolWithTag(Buffer, TAG_WINSTA);
} }
@ -1153,6 +1162,7 @@ BuildDesktopNameList(
DWORD EntryCount; DWORD EntryCount;
ULONG ReturnLength; ULONG ReturnLength;
WCHAR NullWchar; WCHAR NullWchar;
PUNICODE_STRING DesktopName;
Status = IntValidateWindowStationHandle(hWindowStation, Status = IntValidateWindowStationHandle(hWindowStation,
KernelMode, KernelMode,
@ -1175,7 +1185,8 @@ BuildDesktopNameList(
DesktopEntry = DesktopEntry->Flink) DesktopEntry = DesktopEntry->Flink)
{ {
DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry); DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
ReturnLength += ((PUNICODE_STRING)GET_DESKTOP_NAME(DesktopObject))->Length + sizeof(WCHAR); DesktopName = GET_DESKTOP_NAME(DesktopObject);
if (DesktopName) ReturnLength += DesktopName->Length + sizeof(WCHAR);
EntryCount++; EntryCount++;
} }
TRACE("Required size: %d Entry count: %d\n", ReturnLength, EntryCount); TRACE("Required size: %d Entry count: %d\n", ReturnLength, EntryCount);
@ -1218,14 +1229,18 @@ BuildDesktopNameList(
DesktopEntry = DesktopEntry->Flink) DesktopEntry = DesktopEntry->Flink)
{ {
DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry); DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
Status = MmCopyToCaller(lpBuffer, ((PUNICODE_STRING)GET_DESKTOP_NAME(DesktopObject))->Buffer, ((PUNICODE_STRING)GET_DESKTOP_NAME(DesktopObject))->Length); _PRAGMA_WARNING_SUPPRESS(__WARNING_DEREF_NULL_PTR)
DesktopName = GET_DESKTOP_NAME(DesktopObject);/// @todo Don't mess around with the object headers!
if (!DesktopName) continue;
Status = MmCopyToCaller(lpBuffer, DesktopName->Buffer, DesktopName->Length);
if (! NT_SUCCESS(Status)) if (! NT_SUCCESS(Status))
{ {
KeReleaseSpinLock(&WindowStation->Lock, OldLevel); KeReleaseSpinLock(&WindowStation->Lock, OldLevel);
ObDereferenceObject(WindowStation); ObDereferenceObject(WindowStation);
return Status; return Status;
} }
lpBuffer = (PVOID) ((PCHAR) lpBuffer + ((PUNICODE_STRING)GET_DESKTOP_NAME(DesktopObject))->Length); lpBuffer = (PVOID) ((PCHAR)lpBuffer + DesktopName->Length);
Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR)); Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR));
if (! NT_SUCCESS(Status)) if (! NT_SUCCESS(Status))
{ {