Skip to content

Commit b1c6c91

Browse files
committed
[USETUP] Fix invalid use of character count instead of byte count
1 parent a3763c6 commit b1c6c91

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

base/setup/usetup/spapisup/cabinet.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ CabinetOpen(
628628
OBJECT_ATTRIBUTES ObjectAttributes;
629629
IO_STATUS_BLOCK IoStatusBlock;
630630
UNICODE_STRING FileName;
631+
USHORT StringLength;
631632
NTSTATUS NtStatus;
632633

633634
if (CabinetContext->FileOpen)
@@ -732,11 +733,14 @@ CabinetOpen(
732733
the same directory as the current */
733734
wcscpy(CabinetContext->CabinetPrev, CabinetContext->CabinetName);
734735
RemoveFileName(CabinetContext->CabinetPrev);
735-
CabinetNormalizePath(CabinetContext->CabinetPrev, 256);
736+
CabinetNormalizePath(CabinetContext->CabinetPrev, sizeof(CabinetContext->CabinetPrev));
736737
RtlInitAnsiString(&astring, (LPSTR)Buffer);
737-
ustring.Length = wcslen(CabinetContext->CabinetPrev);
738-
ustring.Buffer = CabinetContext->CabinetPrev + ustring.Length;
739-
ustring.MaximumLength = sizeof(CabinetContext->CabinetPrev) - ustring.Length;
738+
739+
/* Initialize ustring with the remaining buffer */
740+
StringLength = (USHORT)wcslen(CabinetContext->CabinetPrev) * sizeof(WCHAR);
741+
ustring.Buffer = CabinetContext->CabinetPrev + StringLength;
742+
ustring.MaximumLength = sizeof(CabinetContext->CabinetPrev) - StringLength;
743+
ustring.Length = 0;
740744
RtlAnsiStringToUnicodeString(&ustring, &astring, FALSE);
741745
Buffer += astring.Length + 1;
742746

@@ -762,9 +766,12 @@ CabinetOpen(
762766
RemoveFileName(CabinetContext->CabinetNext);
763767
CabinetNormalizePath(CabinetContext->CabinetNext, 256);
764768
RtlInitAnsiString(&astring, (LPSTR)Buffer);
765-
ustring.Length = wcslen(CabinetContext->CabinetNext);
766-
ustring.Buffer = CabinetContext->CabinetNext + ustring.Length;
767-
ustring.MaximumLength = sizeof(CabinetContext->CabinetNext) - ustring.Length;
769+
770+
/* Initialize ustring with the remaining buffer */
771+
StringLength = (USHORT)wcslen(CabinetContext->CabinetNext) * sizeof(WCHAR);
772+
ustring.Buffer = CabinetContext->CabinetNext + StringLength;
773+
ustring.MaximumLength = sizeof(CabinetContext->CabinetNext) - StringLength;
774+
ustring.Length = 0;
768775
RtlAnsiStringToUnicodeString(&ustring, &astring, FALSE);
769776
Buffer += astring.Length + 1;
770777

0 commit comments

Comments
 (0)