comctl32: Don't crash when getting a bad image list handle. (try 2)
Francois Gouget
fgouget at codeweavers.com
Mon Sep 19 08:32:16 CDT 2011
---
Don't return from inside the block this time.
dlls/comctl32/imagelist.c | 13 ++++++++++++-
dlls/comctl32/tests/imagelist.c | 17 +++++++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/dlls/comctl32/imagelist.c b/dlls/comctl32/imagelist.c
index ec62370..83b8b44 100644
--- a/dlls/comctl32/imagelist.c
+++ b/dlls/comctl32/imagelist.c
@@ -54,6 +54,7 @@
#include "commoncontrols.h"
#include "imagelist.h"
#include "wine/debug.h"
+#include "wine/exception.h"
WINE_DEFAULT_DEBUG_CHANNEL(imagelist);
@@ -3587,7 +3588,17 @@ static const IImageListVtbl ImageListImpl_Vtbl = {
static inline BOOL is_valid(HIMAGELIST himl)
{
- return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
+ BOOL valid;
+ __TRY
+ {
+ valid = himl && himl->lpVtbl == &ImageListImpl_Vtbl;
+ }
+ __EXCEPT_PAGE_FAULT
+ {
+ valid = FALSE;
+ }
+ __ENDTRY
+ return valid;
}
/*************************************************************************
diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c
index 0441fd0..dc08205 100644
--- a/dlls/comctl32/tests/imagelist.c
+++ b/dlls/comctl32/tests/imagelist.c
@@ -372,6 +372,8 @@ static void test_add_remove(void)
/* destroy it */
ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
+ ok(-1==ImageList_AddIcon((HIMAGELIST)0xdeadbeef, hicon1),"don't crash on bad handle\n");
+
ok(DestroyIcon(hicon1),"icon 1 wasn't deleted\n");
ok(DestroyIcon(hicon2),"icon 2 wasn't deleted\n");
ok(DestroyIcon(hicon3),"icon 3 wasn't deleted\n");
@@ -381,6 +383,8 @@ static void test_imagecount(void)
{
HIMAGELIST himl;
+ ok(0==ImageList_GetImageCount((HIMAGELIST)0xdeadbeef),"don't crash on bad handle\n");
+
if (!pImageList_SetImageCount)
{
win_skip("ImageList_SetImageCount not available\n");
@@ -451,6 +455,8 @@ static void test_DrawIndirect(void)
ok(!pImageList_DrawIndirect(&imldp), "zero hdc succeeded!\n");
imldp.hdcDst = hdc;
ok(!pImageList_DrawIndirect(&imldp),"zero himl succeeded!\n");
+ imldp.himl = (HIMAGELIST)0xdeadbeef;
+ ok(!pImageList_DrawIndirect(&imldp),"bad himl succeeded!\n");
imldp.himl = himl;
REDRAW(hwndfortest);
@@ -1752,11 +1758,15 @@ static void test_iconsize(void)
ok(cy == 0x1abe11ed, "got %d\n", cy);
ImageList_Destroy(himl);
+
+ ret = ImageList_GetIconSize((HIMAGELIST)0xdeadbeef, &cx, &cy);
+ ok(!ret, "got %d\n", ret);
}
-static void test_create(void)
+static void test_create_destroy(void)
{
HIMAGELIST himl;
+ BOOL rc;
/* list with zero or negative image dimensions */
himl = ImageList_Create(0, 0, ILC_COLOR16, 0, 3);
@@ -1773,6 +1783,9 @@ static void test_create(void)
himl = ImageList_Create(-1, 16, ILC_COLOR16, 0, 3);
ok(himl == NULL, "got %p\n", himl);
+
+ rc = ImageList_Destroy((HIMAGELIST)0xdeadbeef);
+ ok(rc == FALSE, "ImageList_Destroy(0xdeadbeef) should fail and not crash\n");
}
static void test_IImageList_Clone(void)
@@ -1912,7 +1925,7 @@ START_TEST(imagelist)
InitCommonControls();
- test_create();
+ test_create_destroy();
test_hotspot();
test_add_remove();
test_imagecount();
--
1.7.5.4
More information about the wine-patches
mailing list