winex11.drv: Improve error handling in bitmap synthesizing code.

Alexander Scott-Johns alexander.scott.johns at googlemail.com
Mon Jan 31 09:50:21 CST 2011


The crash in bug 21543 was caused by not checking the result of
GlobalLock; this patch adds a NULL check.
-------------- next part --------------
From 10936ab46fa2653f96037177de38ff1f7fad665b Mon Sep 17 00:00:00 2001
From: Alexander Scott-Johns <alexander.scott.johns at googlemail.com>
Date: Mon, 31 Jan 2011 15:38:31 +0000
Subject: winex11.drv: Improve error handling in bitmap synthesizing code.

---
 dlls/winex11.drv/clipboard.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/dlls/winex11.drv/clipboard.c b/dlls/winex11.drv/clipboard.c
index e54e15c..3610af7 100644
--- a/dlls/winex11.drv/clipboard.c
+++ b/dlls/winex11.drv/clipboard.c
@@ -1060,21 +1060,23 @@ static BOOL X11DRV_CLIPBOARD_RenderSynthesizedBitmap(Display *display)
         if (lpSource->hData || X11DRV_CLIPBOARD_RenderFormat(display, lpSource))
         {
             HDC hdc;
-            HBITMAP hData;
+            HBITMAP hData = NULL;
             unsigned int offset;
             LPBITMAPINFOHEADER lpbmih;
 
             hdc = GetDC(NULL);
             lpbmih = GlobalLock(lpSource->hData);
+            if (lpbmih)
+            {
+                offset = sizeof(BITMAPINFOHEADER)
+                      + ((lpbmih->biBitCount <= 8) ? (sizeof(RGBQUAD) *
+                        (1 << lpbmih->biBitCount)) : 0);
 
-            offset = sizeof(BITMAPINFOHEADER)
-                  + ((lpbmih->biBitCount <= 8) ? (sizeof(RGBQUAD) *
-                    (1 << lpbmih->biBitCount)) : 0);
-
-            hData = CreateDIBitmap(hdc, lpbmih, CBM_INIT, (LPBYTE)lpbmih +
-                offset, (LPBITMAPINFO) lpbmih, DIB_RGB_COLORS);
+                hData = CreateDIBitmap(hdc, lpbmih, CBM_INIT, (LPBYTE)lpbmih +
+                    offset, (LPBITMAPINFO) lpbmih, DIB_RGB_COLORS);
 
-            GlobalUnlock(lpSource->hData);
+                GlobalUnlock(lpSource->hData);
+            }
             ReleaseDC(NULL, hdc);
 
             if (hData)
-- 
1.7.0.4


More information about the wine-patches mailing list