diff --git a/base/setup/lib/bootsup.c b/base/setup/lib/bootsup.c index 0ef4e8241e9..2f7b43fee3a 100644 --- a/base/setup/lib/bootsup.c +++ b/base/setup/lib/bootsup.c @@ -883,9 +883,9 @@ InstallMbrBootCodeToDisk( #if 0 WCHAR DestinationDevicePathBuffer[MAX_PATH]; - StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), - L"\\Device\\Harddisk%d\\Partition0", - DiskNumber); + RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), + L"\\Device\\Harddisk%d\\Partition0", + DiskNumber); #endif CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2, diff --git a/base/setup/lib/mui.c b/base/setup/lib/mui.c index 1e7eb9def84..27b85b46b99 100644 --- a/base/setup/lib/mui.c +++ b/base/setup/lib/mui.c @@ -298,10 +298,10 @@ AddKbLayoutsToRegistry( { if (uIndex > 19) break; - swprintf(szValueName, L"%u", uIndex + 1); + RtlStringCchPrintfW(szValueName, ARRAYSIZE(szValueName), L"%u", uIndex + 1); RtlInitUnicodeString(&ValueName, szValueName); - swprintf(szLangID, L"0000%s", MuiLayouts[uIndex].LangID); + RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"0000%s", MuiLayouts[uIndex].LangID); if (_wcsicmp(szLangID, MuiLayouts[uIndex].LayoutID) == 0) { @@ -321,7 +321,7 @@ AddKbLayoutsToRegistry( } else { - swprintf(szLangID, L"d%03lu%s", uCount, MuiLayouts[uIndex].LangID); + RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"d%03lu%s", uCount, MuiLayouts[uIndex].LangID); Status = NtSetValueKey(KeyHandle, &ValueName, 0, diff --git a/base/setup/lib/registry.c b/base/setup/lib/registry.c index e36e6a7c76e..54655f51084 100644 --- a/base/setup/lib/registry.c +++ b/base/setup/lib/registry.c @@ -34,9 +34,6 @@ #include "registry.h" -// HACK! -#include - #define NDEBUG #include @@ -1098,8 +1095,8 @@ RegCleanupRegistry( CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 3, InstallPath->Buffer, L"System32\\config", RegistryHives[i].HiveName); - StringCchCopyW(DstPath, ARRAYSIZE(DstPath), SrcPath); - StringCchCatW(DstPath, ARRAYSIZE(DstPath), L".sav"); + RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), SrcPath); + RtlStringCchCatW(DstPath, ARRAYSIZE(DstPath), L".sav"); DPRINT1("Copy hive: %S ==> %S\n", SrcPath, DstPath); Status = SetupCopyFile(SrcPath, DstPath, FALSE); diff --git a/base/setup/lib/settings.c b/base/setup/lib/settings.c index 4e27d0300f2..060c671b411 100644 --- a/base/setup/lib/settings.c +++ b/base/setup/lib/settings.c @@ -422,7 +422,7 @@ DefaultProcessEntry( } wcscpy((PWCHAR)*UserData, KeyName); - wcscpy(DisplayText, KeyValue); + RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue); *Current = (CompareKey ? !_wcsicmp(KeyName, CompareKey) : FALSE); @@ -483,7 +483,7 @@ CreateComputerTypeList( } DPRINT("Computer key: %S\n", KeyName); - wcscpy(ComputerKey, KeyName); + RtlStringCchCopyW(ComputerKey, ARRAYSIZE(ComputerKey), KeyName); INF_FreeData(KeyName); } while (SetupFindNextLine(&Context, &Context)); @@ -548,7 +548,7 @@ GetDisplayIdentifier( BusInstance = 0; while (TRUE) { - swprintf(Buffer, L"%lu", BusInstance); + RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", BusInstance); RtlInitUnicodeString(&KeyName, Buffer); InitializeObjectAttributes(&ObjectAttributes, &KeyName, @@ -584,7 +584,7 @@ GetDisplayIdentifier( while (TRUE) { /* Open the pointer controller instance key */ - swprintf(Buffer, L"%lu", ControllerInstance); + RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", ControllerInstance); RtlInitUnicodeString(&KeyName, Buffer); InitializeObjectAttributes(&ObjectAttributes, &KeyName, @@ -719,7 +719,7 @@ CreateDisplayDriverList( } DPRINT("Display key: %S\n", KeyName); - wcscpy(DisplayKey, KeyName); + RtlStringCchCopyW(DisplayKey, ARRAYSIZE(DisplayKey), KeyName); INF_FreeData(KeyName); } while (SetupFindNextLine(&Context, &Context)); @@ -764,8 +764,8 @@ ProcessComputerFiles( return FALSE; } - wcscpy(SectionName, L"Files."); - wcscat(SectionName, (const wchar_t*)GetListEntryUserData(Entry)); + RtlStringCchPrintfW(SectionName, ARRAYSIZE(SectionName), + L"Files.%s", (PCWSTR)GetListEntryUserData(Entry)); *AdditionalSectionName = SectionName; return TRUE; @@ -813,7 +813,9 @@ ProcessDisplayRegistry( ASSERT(wcslen(ServiceName) < 10); DPRINT1("Service name: '%S'\n", ServiceName); - swprintf(RegPath, L"System\\CurrentControlSet\\Services\\%s", ServiceName); + RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath), + L"System\\CurrentControlSet\\Services\\%s", + ServiceName); RtlInitUnicodeString(&KeyName, RegPath); InitializeObjectAttributes(&ObjectAttributes, &KeyName, @@ -850,9 +852,9 @@ ProcessDisplayRegistry( return FALSE; } - swprintf(RegPath, - L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", - ServiceName); + RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath), + L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", + ServiceName); DPRINT1("RegPath: '%S'\n", RegPath); RtlInitUnicodeString(&KeyName, RegPath); InitializeObjectAttributes(&ObjectAttributes, @@ -1110,7 +1112,7 @@ ProcessLangEntry( } wcscpy((PWCHAR)*UserData, KeyName); - wcscpy(DisplayText, KeyValue); + RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue); *Current = FALSE; diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c index c5a8a6f9815..38d5b58f1fd 100644 --- a/base/setup/lib/setuplib.c +++ b/base/setup/lib/setuplib.c @@ -16,9 +16,6 @@ #include "setuplib.h" -// HACK! -#include - #define NDEBUG #include @@ -147,7 +144,11 @@ CheckUnattendedSetup( DPRINT("INF_GetData() failed for key 'InstallationDirectory'\n"); goto Quit; } - wcscpy(pSetupData->InstallationDirectory, Value); + + RtlStringCchCopyW(pSetupData->InstallationDirectory, + ARRAYSIZE(pSetupData->InstallationDirectory), + Value); + INF_FreeData(Value); } @@ -189,7 +190,9 @@ CheckUnattendedSetup( if (INF_GetData(&Context, NULL, &Value)) { LONG Id = wcstol(Value, NULL, 16); - swprintf(pSetupData->LocaleID, L"%08lx", Id); + RtlStringCchPrintfW(pSetupData->LocaleID, + ARRAYSIZE(pSetupData->LocaleID), + L"%08lx", Id); INF_FreeData(Value); } } @@ -233,8 +236,8 @@ InstallSetupInfFile( if (IniSection) { /* Key "skipmissingfiles" */ - // StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - // L"\"%s\"", L"WinNt5.2"); + // RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + // L"\"%s\"", L"WinNt5.2"); // IniCacheInsertKey(IniSection, NULL, INSERT_LAST, // L"Version", PathBuffer); } @@ -242,20 +245,20 @@ InstallSetupInfFile( IniSection = IniCacheAppendSection(IniCache, L"Data"); if (IniSection) { - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no"); + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no"); IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"UnattendedInstall", PathBuffer); // "floppylessbootpath" (yes/no) - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"\"%s\"", L"winnt"); + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\"%s\"", L"winnt"); IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"ProductType", PathBuffer); - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"\"%s\\\"", pSetupData->SourceRootPath.Buffer); + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\"%s\\\"", pSetupData->SourceRootPath.Buffer); IniCacheInsertKey(IniSection, NULL, INSERT_LAST, L"SourcePath", PathBuffer); @@ -561,7 +564,10 @@ LoadSetupInf( if (!INF_GetData(&Context, NULL, &Value)) return ERROR_CORRUPT_TXTSETUPSIF; - wcscpy(pSetupData->InstallationDirectory, Value); + RtlStringCchCopyW(pSetupData->InstallationDirectory, + ARRAYSIZE(pSetupData->InstallationDirectory), + Value); + INF_FreeData(Value); } diff --git a/base/setup/lib/utils/arcname_tests.c b/base/setup/lib/utils/arcname_tests.c index deba1315523..4f86546a8be 100644 --- a/base/setup/lib/utils/arcname_tests.c +++ b/base/setup/lib/utils/arcname_tests.c @@ -20,8 +20,6 @@ #include -#include - #include "arcname.h" #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\') diff --git a/base/setup/lib/utils/genlist.c b/base/setup/lib/utils/genlist.c index 919b5243ccf..209da600589 100644 --- a/base/setup/lib/utils/genlist.c +++ b/base/setup/lib/utils/genlist.c @@ -21,9 +21,7 @@ CreateGenericList(VOID) { PGENERIC_LIST List; - List = (PGENERIC_LIST)RtlAllocateHeap(ProcessHeap, - 0, - sizeof(GENERIC_LIST)); + List = RtlAllocateHeap(ProcessHeap, 0, sizeof(GENERIC_LIST)); if (List == NULL) return NULL; @@ -70,15 +68,15 @@ AppendGenericListEntry( IN BOOLEAN Current) { PGENERIC_LIST_ENTRY Entry; + SIZE_T TextSize; - Entry = (PGENERIC_LIST_ENTRY)RtlAllocateHeap(ProcessHeap, - 0, - sizeof(GENERIC_LIST_ENTRY) + - (wcslen(Text) + 1) * sizeof(WCHAR)); + TextSize = (wcslen(Text) + 1) * sizeof(WCHAR); + Entry = RtlAllocateHeap(ProcessHeap, 0, + sizeof(GENERIC_LIST_ENTRY) + TextSize); if (Entry == NULL) return FALSE; - wcscpy(Entry->Text, Text); + RtlStringCbCopyW(Entry->Text, TextSize, Text); Entry->List = List; Entry->UserData = UserData; diff --git a/base/setup/lib/utils/regutil.c b/base/setup/lib/utils/regutil.c index 2ede2241649..54bc7c260d6 100644 --- a/base/setup/lib/utils/regutil.c +++ b/base/setup/lib/utils/regutil.c @@ -13,9 +13,6 @@ #include "regutil.h" -// HACK! -#include - #define NDEBUG #include @@ -180,7 +177,8 @@ CreateRegistryFile( // i = 1; /* Try first by just appending the '.old' extension */ - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), + L"%s.%s", PathBuffer, Extension); #if 0 while (DoesFileExist(NULL, PathBuffer2)) { @@ -188,7 +186,8 @@ CreateRegistryFile( if (i <= 0xFFFF) { /* Append '_N.old' extension */ - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s_%lu.%s", PathBuffer, i, Extension); + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), + L"%s_%lu.%s", PathBuffer, i, Extension); ++i; } else @@ -197,7 +196,8 @@ CreateRegistryFile( * Too many old files exist, we will rename the file * using the name of the oldest one. */ - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), + L"%s.%s", PathBuffer, Extension); break; } } diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 9106d0dcab7..b9ba8eea2f4 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -36,9 +36,6 @@ #define NDEBUG #include -// HACK! -#include - /* GLOBALS & LOCALS *********************************************************/ @@ -1679,7 +1676,7 @@ SelectPartitionPage(PINPUT_RECORD Ir) return SELECT_PARTITION_PAGE; } - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"\\Device\\Harddisk%lu\\Partition%lu\\", PartitionList->CurrentDisk->DiskNumber, PartitionList->CurrentPartition->PartitionNumber); @@ -3007,7 +3004,7 @@ FormatPartitionPage(PINPUT_RECORD Ir) } /* Set PartitionRootPath */ - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"\\Device\\Harddisk%lu\\Partition%lu", DiskEntry->DiskNumber, PartEntry->PartitionNumber); @@ -3080,7 +3077,7 @@ CheckFileSystemPage(PINPUT_RECORD Ir) } /* Set PartitionRootPath */ - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"\\Device\\Harddisk%lu\\Partition%lu", DiskEntry->DiskNumber, PartEntry->PartitionNumber); @@ -3171,7 +3168,7 @@ BuildInstallPaths(PWSTR InstallDir, /* Create 'USetupData.DestinationRootPath' string */ RtlFreeUnicodeString(&USetupData.DestinationRootPath); - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"\\Device\\Harddisk%lu\\Partition%lu\\", DiskEntry->DiskNumber, PartEntry->PartitionNumber); @@ -3188,7 +3185,7 @@ BuildInstallPaths(PWSTR InstallDir, /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ /* Create 'USetupData.DestinationArcPath' */ RtlFreeUnicodeString(&USetupData.DestinationArcPath); - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", DiskEntry->BiosDiskNumber, PartEntry->PartitionNumber); @@ -3598,8 +3595,8 @@ AddSectionToCopyQueue(HINF InfFile, /* Installation path */ DPRINT("InstallationPath: '%S'\n", DirKeyValue); - StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), - USetupData.SourceRootDir.Buffer); + RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), + USetupData.SourceRootDir.Buffer); DPRINT("InstallationPath(2): '%S'\n", CompleteOrigDirName); } @@ -3608,8 +3605,8 @@ AddSectionToCopyQueue(HINF InfFile, /* Absolute path */ DPRINT("AbsolutePath: '%S'\n", DirKeyValue); - StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), - DirKeyValue); + RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), + DirKeyValue); DPRINT("AbsolutePath(2): '%S'\n", CompleteOrigDirName); } @@ -3684,7 +3681,7 @@ PrepareCopyPageInfFile(HINF InfFile, */ /* Get destination path */ - StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), USetupData.DestinationPath.Buffer); + RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), USetupData.DestinationPath.Buffer); DPRINT("FullPath(1): '%S'\n", PathBuffer); @@ -3726,8 +3723,8 @@ PrepareCopyPageInfFile(HINF InfFile, /* Installation path */ DPRINT("InstallationPath: '%S'\n", DirKeyValue); - StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), - USetupData.DestinationPath.Buffer); + RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), + USetupData.DestinationPath.Buffer); DPRINT("InstallationPath(2): '%S'\n", PathBuffer); } @@ -4321,7 +4318,7 @@ BootLoaderPage(PINPUT_RECORD Ir) CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); RtlFreeUnicodeString(&USetupData.SystemRootPath); - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), L"\\Device\\Harddisk%lu\\Partition%lu\\", PartitionList->SystemPartition->DiskEntry->DiskNumber, PartitionList->SystemPartition->PartitionNumber); @@ -4620,7 +4617,7 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir) } /* Step 2: Write the MBR */ - StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), + RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), L"\\Device\\Harddisk%d\\Partition0", PartitionList->SystemPartition->DiskEntry->DiskNumber); Status = InstallMbrBootCodeToDisk(&USetupData.SystemRootPath, diff --git a/base/setup/usetup/usetup.h b/base/setup/usetup/usetup.h index 2bbb879c546..61971f1432b 100644 --- a/base/setup/usetup/usetup.h +++ b/base/setup/usetup/usetup.h @@ -52,6 +52,7 @@ #include + /* Setup library headers */ #include #include <../lib/setuplib.h>