From cead3c26acd6fdce7e497ae955eab76cb865976a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 2 Jun 2017 00:05:53 +0000 Subject: [PATCH] [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 --- reactos/sdk/tools/mkhive/binhive.c | 2 +- reactos/sdk/tools/mkhive/reginf.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/reactos/sdk/tools/mkhive/binhive.c b/reactos/sdk/tools/mkhive/binhive.c index e7eb11f4684..3d99346d9a3 100644 --- a/reactos/sdk/tools/mkhive/binhive.c +++ b/reactos/sdk/tools/mkhive/binhive.c @@ -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"); diff --git a/reactos/sdk/tools/mkhive/reginf.c b/reactos/sdk/tools/mkhive/reginf.c index f787c3525af..931fc2feab3 100644 --- a/reactos/sdk/tools/mkhive/reginf.c +++ b/reactos/sdk/tools/mkhive/reginf.c @@ -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: