[PATCH] shell32: Check for NULL lpText (Coverity)

Marcus Meissner marcus at jet.franken.de
Tue Dec 1 16:14:10 CST 2009


Hi,

Check for lpText==NULL ... Calling code
(FileMenu_AppendItemAW) seems to assume lpText NULL is possible.

Also check HeapAlloc return value, one potential cause of this.

Ciao, Marcus
---
 dlls/shell32/shlmenu.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/dlls/shell32/shlmenu.c b/dlls/shell32/shlmenu.c
index efdd6b5..294ac5c 100644
--- a/dlls/shell32/shlmenu.c
+++ b/dlls/shell32/shlmenu.c
@@ -329,8 +329,12 @@ static BOOL FileMenu_AppendItemW(
 
 	if (lpText != FM_SEPARATOR)
 	{
-	  int len = strlenW (lpText);
-          myItem = SHAlloc(sizeof(FMITEM) + len*sizeof(WCHAR));
+	  int len;
+
+	  if (!lpText)
+               return FALSE;
+	  len = strlenW (lpText);
+	  myItem = SHAlloc(sizeof(FMITEM) + len*sizeof(WCHAR));
 	  strcpyW (myItem->szItemText, lpText);
 	  myItem->cchItemText = len;
 	  myItem->iIconIndex = icon;
@@ -398,6 +402,7 @@ BOOL WINAPI FileMenu_AppendItemAW(
 	{
 	  DWORD len = MultiByteToWideChar( CP_ACP, 0, lpText, -1, NULL, 0 );
 	  LPWSTR lpszText = HeapAlloc ( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+	  if (!lpszText) return FALSE;
 	  MultiByteToWideChar( CP_ACP, 0, lpText, -1, lpszText, len );
 	  ret = FileMenu_AppendItemW(hMenu, lpszText, uID, icon, hMenuPopup, nItemHeight);
 	  HeapFree( GetProcessHeap(), 0, lpszText );
-- 
1.5.6



More information about the wine-patches mailing list