[SETUPLIB][USETUP] Use NT RTL String Safe functions instead of Win32-oriented ones...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 3 Sep 2017 20:05:11 +0000 (20:05 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Oct 2018 22:58:46 +0000 (00:58 +0200)
Based on:
svn path=/branches/setup_improvements/; revision=75755
svn path=/branches/setup_improvements/; revision=75757

base/setup/lib/bootsup.c
base/setup/lib/mui.c
base/setup/lib/registry.c
base/setup/lib/settings.c
base/setup/lib/setuplib.c
base/setup/lib/utils/arcname_tests.c
base/setup/lib/utils/genlist.c
base/setup/lib/utils/regutil.c
base/setup/usetup/usetup.c
base/setup/usetup/usetup.h

index 0ef4e82..2f7b43f 100644 (file)
@@ -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,
index 1e7eb9d..27b85b4 100644 (file)
@@ -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,
index e36e6a7..54655f5 100644 (file)
@@ -34,9 +34,6 @@
 
 #include "registry.h"
 
-// HACK!
-#include <strsafe.h>
-
 #define NDEBUG
 #include <debug.h>
 
@@ -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);
index 4e27d03..060c671 100644 (file)
@@ -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;
 
index c5a8a6f..38d5b58 100644 (file)
@@ -16,9 +16,6 @@
 
 #include "setuplib.h"
 
-// HACK!
-#include <strsafe.h>
-
 #define NDEBUG
 #include <debug.h>
 
@@ -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);
     }
 
index deba131..4f86546 100644 (file)
@@ -20,8 +20,6 @@
 
 #include <ntstatus.h>
 
-#include <strsafe.h>
-
 #include "arcname.h"
 
 #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
index 919b524..209da60 100644 (file)
@@ -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;
 
index 2ede224..54bc7c2 100644 (file)
@@ -13,9 +13,6 @@
 
 #include "regutil.h"
 
-// HACK!
-#include <strsafe.h>
-
 #define NDEBUG
 #include <debug.h>
 
@@ -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;
             }
         }
index 9106d0d..b9ba8ee 100644 (file)
@@ -36,9 +36,6 @@
 #define NDEBUG
 #include <debug.h>
 
-// HACK!
-#include <strsafe.h>
-
 
 /* 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,
index 2bbb879..61971f1 100644 (file)
@@ -52,6 +52,7 @@
 
 #include <ntstrsafe.h>
 
+
 /* Setup library headers */
 #include <reactos/rosioctl.h>
 #include <../lib/setuplib.h>