From: Nikolay Sivov Subject: wshom.ocx: Fix BSTR allocation for string registry values (Valgrind) Message-Id: <5534F751.20503@codeweavers.com> Date: Mon, 20 Apr 2015 15:55:45 +0300 --- From 7f91485786260ba8d6fdc4c7aabda08fa4ab14f6 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 20 Apr 2015 15:53:32 +0300 Subject: [PATCH] wshom.ocx: Fix BSTR allocation for string registry values (Valgrind) --- dlls/wshom.ocx/shell.c | 2 +- dlls/wshom.ocx/tests/wshom.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dlls/wshom.ocx/shell.c b/dlls/wshom.ocx/shell.c index 826e290..f9ec9dc 100644 --- a/dlls/wshom.ocx/shell.c +++ b/dlls/wshom.ocx/shell.c @@ -1376,7 +1376,7 @@ static HRESULT WINAPI WshShell3_RegRead(IWshShell3 *iface, BSTR name, VARIANT *v case REG_SZ: case REG_EXPAND_SZ: V_VT(value) = VT_BSTR; - V_BSTR(value) = SysAllocStringLen((WCHAR*)data, datalen - sizeof(WCHAR)); + V_BSTR(value) = SysAllocString((WCHAR*)data); if (!V_BSTR(value)) hr = E_OUTOFMEMORY; break; diff --git a/dlls/wshom.ocx/tests/wshom.c b/dlls/wshom.ocx/tests/wshom.c index 9591c5c..46ffc58 100644 --- a/dlls/wshom.ocx/tests/wshom.c +++ b/dlls/wshom.ocx/tests/wshom.c @@ -276,7 +276,7 @@ static void test_registry(void) { static const WCHAR keypathW[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\', 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t','\\',0}; - + static const WCHAR regsz2W[] = {'r','e','g','s','z','2',0}; static const WCHAR regszW[] = {'r','e','g','s','z',0}; static const WCHAR regdwordW[] = {'r','e','g','d','w','o','r','d',0}; static const WCHAR regbinaryW[] = {'r','e','g','b','i','n','a','r','y',0}; @@ -332,6 +332,9 @@ static void test_registry(void) ret = RegSetValueExA(root, "regsz", 0, REG_SZ, (const BYTE*)"foobar", 7); ok(ret == 0, "got %d\n", ret); + ret = RegSetValueExA(root, "regsz2", 0, REG_SZ, (const BYTE*)"foobar\0f", 9); + ok(ret == 0, "got %d\n", ret); + ret = RegSetValueExA(root, "regmultisz", 0, REG_MULTI_SZ, (const BYTE*)"foo\0bar\0", 9); ok(ret == 0, "got %d\n", ret); @@ -355,6 +358,18 @@ static void test_registry(void) VariantClear(&value); SysFreeString(name); + /* REG_SZ with embedded NULL */ + lstrcpyW(pathW, keypathW); + lstrcatW(pathW, regsz2W); + name = SysAllocString(pathW); + VariantInit(&value); + hr = IWshShell3_RegRead(sh3, name, &value); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value)); + ok(SysStringLen(V_BSTR(&value)) == 6, "len %d\n", SysStringLen(V_BSTR(&value))); + VariantClear(&value); + SysFreeString(name); + /* REG_DWORD */ lstrcpyW(pathW, keypathW); lstrcatW(pathW, regdwordW); -- 2.1.4