regedit: Null-terminate REG_EXPAND_SZ and REG_MULTI_SZ hex data during concatenation if we reach EOF.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2017-07-10 11:28:17 +00:00 committed by Alexandre Julliard
parent 82e6713b75
commit 7f11a24fee
2 changed files with 25 additions and 19 deletions

View File

@ -504,6 +504,27 @@ static void free_parser_data(struct parser *parser)
parser->data_size = 0;
}
static void prepare_hex_string_data(struct parser *parser)
{
if (parser->data_type == REG_EXPAND_SZ || parser->data_type == REG_MULTI_SZ)
{
BYTE *data = parser->data;
if (data[parser->data_size - 1] != 0)
{
data[parser->data_size] = 0;
parser->data_size++;
}
if (!parser->is_unicode)
{
parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size);
parser->data_size *= sizeof(WCHAR);
HeapFree(GetProcessHeap(), 0, data);
}
}
}
enum reg_versions {
REG_VERSION_31,
REG_VERSION_40,
@ -852,23 +873,7 @@ static WCHAR *hex_data_state(struct parser *parser, WCHAR *pos)
return line;
}
if (parser->data_type == REG_EXPAND_SZ || parser->data_type == REG_MULTI_SZ)
{
BYTE *data = parser->data;
if (data[parser->data_size - 1] != 0x00)
{
data[parser->data_size] = 0x00;
parser->data_size++;
}
if (!parser->is_unicode)
{
parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size);
parser->data_size *= sizeof(WCHAR);
HeapFree(GetProcessHeap(), 0, data);
}
}
prepare_hex_string_data(parser);
set_state(parser, SET_VALUE);
return line;
@ -903,6 +908,7 @@ static WCHAR *hex_multiline_state(struct parser *parser, WCHAR *pos)
if (!(line = get_line(parser->file)))
{
prepare_hex_string_data(parser);
set_state(parser, SET_VALUE);
return pos;
}

View File

@ -500,7 +500,7 @@ static void test_basic_import(void)
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
"\"Wine17b\"=hex(2):25,50,41,54,48,25,\\");
verify_reg(hkey, "Wine17b", REG_EXPAND_SZ, "%PATH%", 7, TODO_REG_SIZE | TODO_REG_DATA);
verify_reg(hkey, "Wine17b", REG_EXPAND_SZ, "%PATH%", 7, 0);
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
@ -510,7 +510,7 @@ static void test_basic_import(void)
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
"\"Wine17d\"=hex(7):4c,69,6e,65,\\");
verify_reg(hkey, "Wine17d", REG_MULTI_SZ, "Line", 5, TODO_REG_SIZE | TODO_REG_DATA);
verify_reg(hkey, "Wine17d", REG_MULTI_SZ, "Line", 5, 0);
exec_import_str("REGEDIT4\n\n"
"[HKEY_CURRENT_USER\\" KEY_BASE "]\n"