From 61a4200162a3943dea88e401d9bef6dae2a66285 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 16 Nov 2009 20:09:48 +0100 Subject: [PATCH] shell32: Fix setting of NULL arguments in IShellLink. --- dlls/shell32/shelllink.c | 25 +++++++++++++++++-------- dlls/shell32/tests/shelllink.c | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index 414cc54e8ab..3b161705cc7 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -1497,9 +1497,13 @@ static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR psz TRACE("(%p)->(args=%s)\n",This, pszArgs); HeapFree(GetProcessHeap(), 0, This->sArgs); - This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs); - if( !This->sArgs ) - return E_OUTOFMEMORY; + if (pszArgs) + { + This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs); + if( !This->sArgs ) + return E_OUTOFMEMORY; + } + else This->sArgs = NULL; This->bDirty = TRUE; @@ -1877,11 +1881,16 @@ static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR ps TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs)); HeapFree(GetProcessHeap(), 0, This->sArgs); - This->sArgs = HeapAlloc( GetProcessHeap(), 0, - (lstrlenW( pszArgs )+1)*sizeof (WCHAR) ); - if ( !This->sArgs ) - return E_OUTOFMEMORY; - lstrcpyW( This->sArgs, pszArgs ); + if (pszArgs) + { + This->sArgs = HeapAlloc( GetProcessHeap(), 0, + (lstrlenW( pszArgs )+1)*sizeof (WCHAR) ); + if ( !This->sArgs ) + return E_OUTOFMEMORY; + lstrcpyW( This->sArgs, pszArgs ); + } + else This->sArgs = NULL; + This->bDirty = TRUE; return S_OK; diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c index 2f20200c67a..25354718601 100644 --- a/dlls/shell32/tests/shelllink.c +++ b/dlls/shell32/tests/shelllink.c @@ -275,6 +275,20 @@ static void test_get_set(void) ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r); ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer); + strcpy(buffer,"garbage"); + r = IShellLinkA_SetArguments(sl, NULL); + ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r); + r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer)); + ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r); + ok(!buffer[0] || lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer); + + strcpy(buffer,"garbage"); + r = IShellLinkA_SetArguments(sl, ""); + ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r); + r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer)); + ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r); + ok(!buffer[0], "GetArguments returned '%s'\n", buffer); + /* Test Getting / Setting showcmd */ i=0xdeadbeef; r = IShellLinkA_GetShowCmd(sl, &i);