[PATCH] shell32/shelllink: Fix NULL path handling in SetIconLocation().
Nikolay Sivov
nsivov at codeweavers.com
Sun Sep 30 11:39:08 CDT 2018
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
dlls/shell32/shelllink.c | 38 ++++++++++++++++++++--------------
dlls/shell32/tests/shelllink.c | 29 +++++++++++++++++++++++++-
2 files changed, 51 insertions(+), 16 deletions(-)
diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c
index 0380ac9e7a..9a61ea100d 100644
--- a/dlls/shell32/shelllink.c
+++ b/dlls/shell32/shelllink.c
@@ -1464,19 +1464,22 @@ static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA *iface, LPSTR ps
return S_OK;
}
-static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA *iface, LPCSTR pszIconPath,
- INT iIcon)
+static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA *iface, LPCSTR path, INT icon)
{
IShellLinkImpl *This = impl_from_IShellLinkA(iface);
- WCHAR *pathW;
+ WCHAR *pathW = NULL;
HRESULT hr;
- TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
+ TRACE("(%p)->(path=%s icon=%u)\n", This, debugstr_a(path), icon);
- pathW = heap_strdupAtoW(pszIconPath);
- if (!pathW) return E_OUTOFMEMORY;
+ if (path)
+ {
+ pathW = heap_strdupAtoW(path);
+ if (!pathW)
+ return E_OUTOFMEMORY;
+ }
- hr = IShellLinkW_SetIconLocation(&This->IShellLinkW_iface, pathW, iIcon);
+ hr = IShellLinkW_SetIconLocation(&This->IShellLinkW_iface, path ? pathW : NULL, icon);
heap_free(pathW);
return hr;
@@ -1927,19 +1930,24 @@ static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR
return S_OK;
}
-static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
+static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, const WCHAR *path, INT icon)
{
IShellLinkImpl *This = impl_from_IShellLinkW(iface);
- TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
+ TRACE("(%p)->(path=%s icon=%u)\n", This, debugstr_w(path), icon);
heap_free(This->sIcoPath);
- This->sIcoPath = heap_alloc((lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
- if ( !This->sIcoPath )
- return E_OUTOFMEMORY;
- lstrcpyW( This->sIcoPath, pszIconPath );
-
- This->iIcoNdx = iIcon;
+ if (path)
+ {
+ size_t len = (strlenW(path) + 1) * sizeof(WCHAR);
+ This->sIcoPath = heap_alloc(len);
+ if (!This->sIcoPath)
+ return E_OUTOFMEMORY;
+ memcpy(This->sIcoPath, path, len);
+ }
+ else
+ This->sIcoPath = NULL;
+ This->iIcoNdx = icon;
This->bDirty = TRUE;
return S_OK;
diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c
index 65e9a6dd55..3bfd9cbe38 100644
--- a/dlls/shell32/tests/shelllink.c
+++ b/dlls/shell32/tests/shelllink.c
@@ -973,6 +973,7 @@ static void test_shdefextracticon(void)
static void test_GetIconLocation(void)
{
+ IShellLinkW *slW;
IShellLinkA *sl;
const char *str;
char buffer[INFOTIPSIZE], mypath[MAX_PATH];
@@ -1026,8 +1027,34 @@ static void test_GetIconLocation(void)
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(lstrcmpiA(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
- ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
+ ok(i == 0xbabecafe, "GetIconLocation returned %#x.\n", i);
+ r = IShellLinkA_SetIconLocation(sl, NULL, 0xcafefe);
+ ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
+
+ i = 0xdeadbeef;
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(!*buffer, "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0xcafefe, "GetIconLocation returned %#x.\n", i);
+
+ r = IShellLinkA_QueryInterface(sl, &IID_IShellLinkW, (void **)&slW);
+ ok(SUCCEEDED(r), "Failed to get IShellLinkW, hr %#x.\n", r);
+
+ str = "c:\\nonexistent\\file";
+ r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
+ ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
+
+ r = IShellLinkA_SetIconLocation(sl, NULL, 0xcafefe);
+ ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
+
+ i = 0xdeadbeef;
+ r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
+ ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
+ ok(!*buffer, "GetIconLocation returned '%s'\n", buffer);
+ ok(i == 0xcafefe, "GetIconLocation returned %#x.\n", i);
+
+ IShellLinkW_Release(slW);
IShellLinkA_Release(sl);
}
--
2.19.0
More information about the wine-devel
mailing list