Nikolay Sivov : shell32: Avoid zero length allocations when converting path in ExtractIconA() ( Valgrind).
Alexandre Julliard
julliard at winehq.org
Mon Jun 5 16:56:29 CDT 2017
Module: wine
Branch: master
Commit: 1a5561c0cf202805436dd58635f6f61b8254d3d3
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1a5561c0cf202805436dd58635f6f61b8254d3d3
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Jun 5 02:10:28 2017 +0300
shell32: Avoid zero length allocations when converting path in ExtractIconA() (Valgrind).
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/shell32/shell32_main.c | 15 +++++++--------
dlls/shell32/shell32_main.h | 15 +++++++++++++++
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c
index 04924c0..34b906c 100644
--- a/dlls/shell32/shell32_main.c
+++ b/dlls/shell32/shell32_main.c
@@ -846,17 +846,16 @@ HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
/*************************************************************************
* ExtractIconA [SHELL32.@]
*/
-HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
-{
+HICON WINAPI ExtractIconA(HINSTANCE hInstance, const char *file, UINT nIconIndex)
+{
+ WCHAR *fileW;
HICON ret;
- INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
- LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
- TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
+ TRACE("%p %s %d\n", hInstance, debugstr_a(file), nIconIndex);
- MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
- ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
- HeapFree(GetProcessHeap(), 0, lpwstrFile);
+ fileW = strdupAtoW(file);
+ ret = ExtractIconW(hInstance, fileW, nIconIndex);
+ HeapFree(GetProcessHeap(), 0, fileW);
return ret;
}
diff --git a/dlls/shell32/shell32_main.h b/dlls/shell32/shell32_main.h
index 941ca74..fc2a5ba 100644
--- a/dlls/shell32/shell32_main.h
+++ b/dlls/shell32/shell32_main.h
@@ -236,4 +236,19 @@ static inline WCHAR *strdupW(const WCHAR *src)
return dest;
}
+static inline WCHAR *strdupAtoW(const char *str)
+{
+ WCHAR *ret;
+ DWORD len;
+
+ if (!str) return NULL;
+
+ len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if (ret)
+ MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+
+ return ret;
+}
+
#endif
More information about the wine-cvs
mailing list