[MKHIVE]: Fix string byte size vs. count in number of characters confusion in append_multi_sz_value(); this was already OK in wine's code. Should fix corrupted multi-string entries in the livecd registry hives, for example...

In addition, always open the hive file to be created in write mode only.
CORE-13347

svn path=/trunk/; revision=74740
This commit is contained in:
Hermès Bélusca-Maïto 2017-06-02 00:05:53 +00:00
parent b03f8990c0
commit cead3c26ac
2 changed files with 7 additions and 8 deletions

View file

@ -41,7 +41,7 @@ ExportBinaryHive(
printf(" Creating binary hive: %s\n", FileName);
/* Create new hive file */
File = fopen(FileName, "w+b");
File = fopen(FileName, "wb");
if (File == NULL)
{
printf(" Error creating/opening file\n");

View file

@ -120,11 +120,10 @@ append_multi_sz_value(
IN HKEY KeyHandle,
IN PWCHAR ValueName,
IN PWCHAR Strings,
IN ULONG StringSize)
IN ULONG StringSize) // In characters
{
ULONG Size;
ULONG Size, Total; // In bytes
ULONG Type;
ULONG Total;
PWCHAR Buffer;
PWCHAR p;
size_t len;
@ -139,7 +138,7 @@ append_multi_sz_value(
if ((Error != ERROR_SUCCESS) || (Type != REG_MULTI_SZ))
return;
Buffer = malloc ((Size + StringSize) * sizeof(WCHAR));
Buffer = malloc(Size + StringSize * sizeof(WCHAR));
if (Buffer == NULL)
return;
@ -164,9 +163,9 @@ append_multi_sz_value(
if (*p == 0) /* not found, need to append it */
{
memcpy (p, Strings, len);
memcpy(p, Strings, len * sizeof(WCHAR));
p[len] = 0;
Total += len;
Total += len * sizeof(WCHAR);
}
Strings += len;
}
@ -179,7 +178,7 @@ append_multi_sz_value(
0,
REG_MULTI_SZ,
(PUCHAR)Buffer,
Total * sizeof(WCHAR));
Total + sizeof(WCHAR));
}
done: