gdi32: Avoid null pointer dereference in CreateDIBSection.

This commit is contained in:
Nikolay Sivov 2008-05-10 11:14:29 +04:00 committed by Alexandre Julliard
parent 02bf65a752
commit 1441311d36
2 changed files with 12 additions and 0 deletions

View File

@ -1258,6 +1258,11 @@ HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage,
DWORD compression, sizeImage;
void *mapBits = NULL;
if(!bmi){
if(bits) *bits = NULL;
return NULL;
}
if (((bitmap_type = DIB_GetBitmapInfo( &bmi->bmiHeader, &width, &height,
&planes, &bpp, &compression, &sizeImage )) == -1))
return 0;

View File

@ -416,6 +416,13 @@ static void test_dibsections(void)
pbmi->bmiHeader.biCompression = BI_RGB;
SetLastError(0xdeadbeef);
/* invalid pointer for BITMAPINFO
(*bits should be NULL on error) */
bits = (BYTE*)0xdeadbeef;
hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");