https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b1c6c91d1f93f4bdf5455895736b6055047c2cd4

commit b1c6c91d1f93f4bdf5455895736b6055047c2cd4
Author:     Timo Kreuzer <[email protected]>
AuthorDate: Wed Jul 21 10:26:42 2021 +0200
Commit:     Timo Kreuzer <[email protected]>
CommitDate: Fri Jul 23 22:03:48 2021 +0200

    [USETUP] Fix invalid use of character count instead of byte count
---
 base/setup/usetup/spapisup/cabinet.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/base/setup/usetup/spapisup/cabinet.c 
b/base/setup/usetup/spapisup/cabinet.c
index 8d8391a3250..46ae4e5d5d5 100644
--- a/base/setup/usetup/spapisup/cabinet.c
+++ b/base/setup/usetup/spapisup/cabinet.c
@@ -628,6 +628,7 @@ CabinetOpen(
     OBJECT_ATTRIBUTES ObjectAttributes;
     IO_STATUS_BLOCK IoStatusBlock;
     UNICODE_STRING FileName;
+    USHORT StringLength;
     NTSTATUS NtStatus;
 
     if (CabinetContext->FileOpen)
@@ -732,11 +733,14 @@ CabinetOpen(
            the same directory as the current */
         wcscpy(CabinetContext->CabinetPrev, CabinetContext->CabinetName);
         RemoveFileName(CabinetContext->CabinetPrev);
-        CabinetNormalizePath(CabinetContext->CabinetPrev, 256);
+        CabinetNormalizePath(CabinetContext->CabinetPrev, 
sizeof(CabinetContext->CabinetPrev));
         RtlInitAnsiString(&astring, (LPSTR)Buffer);
-        ustring.Length = wcslen(CabinetContext->CabinetPrev);
-        ustring.Buffer = CabinetContext->CabinetPrev + ustring.Length;
-        ustring.MaximumLength = sizeof(CabinetContext->CabinetPrev) - 
ustring.Length;
+
+        /* Initialize ustring with the remaining buffer */
+        StringLength = (USHORT)wcslen(CabinetContext->CabinetPrev) * 
sizeof(WCHAR);
+        ustring.Buffer = CabinetContext->CabinetPrev + StringLength;
+        ustring.MaximumLength = sizeof(CabinetContext->CabinetPrev) - 
StringLength;
+        ustring.Length = 0;
         RtlAnsiStringToUnicodeString(&ustring, &astring, FALSE);
         Buffer += astring.Length + 1;
 
@@ -762,9 +766,12 @@ CabinetOpen(
         RemoveFileName(CabinetContext->CabinetNext);
         CabinetNormalizePath(CabinetContext->CabinetNext, 256);
         RtlInitAnsiString(&astring, (LPSTR)Buffer);
-        ustring.Length = wcslen(CabinetContext->CabinetNext);
-        ustring.Buffer = CabinetContext->CabinetNext + ustring.Length;
-        ustring.MaximumLength = sizeof(CabinetContext->CabinetNext) - 
ustring.Length;
+
+        /* Initialize ustring with the remaining buffer */
+        StringLength = (USHORT)wcslen(CabinetContext->CabinetNext) * 
sizeof(WCHAR);
+        ustring.Buffer = CabinetContext->CabinetNext + StringLength;
+        ustring.MaximumLength = sizeof(CabinetContext->CabinetNext) - 
StringLength;
+        ustring.Length = 0;
         RtlAnsiStringToUnicodeString(&ustring, &astring, FALSE);
         Buffer += astring.Length + 1;
 

Reply via email to