Commit a8150b53 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

wshom.ocx: Fix BSTR allocation for string registry values (Valgrind).

parent 604c4dba
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment