[NTOS]: Addendum to r75142: Use strsafe printf functions (suggested by Thomas).
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 19 Jun 2017 20:37:36 +0000 (20:37 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 19 Jun 2017 20:37:36 +0000 (20:37 +0000)
svn path=/trunk/; revision=75144

reactos/ntoskrnl/config/cmsysini.c

index dd10af2..2785f40 100644 (file)
@@ -621,9 +621,9 @@ UseSet:
     ASSERT(Disposition == REG_CREATED_NEW_KEY);
 
     /* Initialize the target link name */
-    swprintf(UnicodeBuffer,
-             L"\\Registry\\Machine\\System\\ControlSet%03ld",
-             ControlSet);
+    RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
+                       L"\\Registry\\Machine\\System\\ControlSet%03ld",
+                       ControlSet);
     RtlInitUnicodeString(&KeyName, UnicodeBuffer);
 
     /* Set the value */
@@ -696,7 +696,8 @@ UseSet:
     }
 
     /* Build the profile name */
-    swprintf(UnicodeBuffer, L"%04ld", HwProfile);
+    RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
+                       L"%04ld", HwProfile);
     RtlInitUnicodeString(&KeyName, UnicodeBuffer);
 
     /* Open the associated key */
@@ -744,10 +745,10 @@ UseSet:
         ASSERT(Disposition == REG_CREATED_NEW_KEY);
 
         /* Create the profile name */
-        swprintf(UnicodeBuffer,
-                L"\\Registry\\Machine\\System\\CurrentControlSet\\"
-                L"Hardware Profiles\\%04ld",
-                HwProfile);
+        RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
+                           L"\\Registry\\Machine\\System\\CurrentControlSet\\"
+                           L"Hardware Profiles\\%04ld",
+                           HwProfile);
         RtlInitUnicodeString(&KeyName, UnicodeBuffer);
 
         /* Set it */
@@ -2147,8 +2148,8 @@ CmpSetVersionData(VOID)
     HANDLE MicrosoftKeyHandle = NULL;
     HANDLE WindowsNtKeyHandle = NULL;
     HANDLE CurrentVersionKeyHandle = NULL;
-    WCHAR Buffer[128]; // Buffer large enough to contain a full ULONG in decimal representation,
-                       // and the full 'CurrentType' string.
+    WCHAR Buffer[128]; // Buffer large enough to contain a full ULONG in decimal
+                       // representation, and the full 'CurrentType' string.
 
     /*
      * Open the 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' key
@@ -2267,20 +2268,20 @@ CmpSetVersionData(VOID)
 
     /* Set the 'CurrentType' value */
     RtlInitUnicodeString(&ValueName, L"CurrentType");
-
-    swprintf(Buffer, L"%s %s",
+    RtlStringCbPrintfW(Buffer, sizeof(Buffer),
+                       L"%s %s",
 #ifdef CONFIG_SMP
-             L"Multiprocessor"
+                       L"Multiprocessor"
 #else
-             L"Uniprocessor"
+                       L"Uniprocessor"
 #endif
-             ,
+                       ,
 #if (DBG == 1)
-             L"Checked"
+                       L"Checked"
 #else
-             L"Free"
+                       L"Free"
 #endif
-             );
+                       );
     RtlInitUnicodeString(&ValueData, Buffer);
     NtSetValueKey(CurrentVersionKeyHandle,
                   &ValueName,