[FREELDR] Use RtlStringCbPrintfA instead of sprintf
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 28 Apr 2019 15:48:58 +0000 (17:48 +0200)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 20 Jul 2019 11:56:18 +0000 (13:56 +0200)
Fixes GCC 8 warnings like:
boot/freeldr/freeldr/disk/scsiport.c:806:31: error: 'partition(0)' directive writing 12 bytes into a region of size between 1 and 64 [-Werror=format-overflow=]
     sprintf(PartitionName, "%spartition(0)", ArcName);
                               ^~~~~~~~~~~~
boot/freeldr/freeldr/disk/scsiport.c:806:5: note: 'sprintf' output between 13 and 76 bytes into a destination of size 64
     sprintf(PartitionName, "%spartition(0)", ArcName);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

boot/freeldr/freeldr/disk/scsiport.c
boot/freeldr/freeldr/include/freeldr.h
boot/freeldr/freeldr/linuxboot.c
boot/freeldr/freeldr/ntldr/wlregistry.c

index 7f206aa..0c0a0fa 100644 (file)
@@ -803,7 +803,7 @@ SpiScanDevice(
     CHAR PartitionName[64];
 
     /* Register device with partition(0) suffix */
-    sprintf(PartitionName, "%spartition(0)", ArcName);
+    RtlStringCbPrintfA(PartitionName, sizeof(PartitionName), "%spartition(0)", ArcName);
     FsRegisterDevice(PartitionName, &DiskVtbl);
 
     /* Read device partition table */
@@ -817,8 +817,11 @@ SpiScanDevice(
             {
                 if (PartitionBuffer->PartitionEntry[i].PartitionType != PARTITION_ENTRY_UNUSED)
                 {
-                    sprintf(PartitionName, "%spartition(%lu)",
-                            ArcName, PartitionBuffer->PartitionEntry[i].PartitionNumber);
+                    RtlStringCbPrintfA(PartitionName,
+                                       sizeof(PartitionName),
+                                       "%spartition(%lu)",
+                                       ArcName,
+                                       PartitionBuffer->PartitionEntry[i].PartitionNumber);
                     FsRegisterDevice(PartitionName, &DiskVtbl);
                 }
             }
index b62d4e5..82a6b89 100644 (file)
@@ -50,6 +50,7 @@
 #include <internal/hal.h>
 #include <drivers/pci/pci.h>
 #include <winerror.h>
+#include <ntstrsafe.h>
 #else
 #include <ntsup.h>
 #endif
index 54b16a6..2325894 100644 (file)
@@ -341,7 +341,7 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
     CHAR  StatusText[260];
     PVOID LoadAddress;
 
-    sprintf(StatusText, "Loading %s", LinuxKernelName);
+    RtlStringCbPrintfA(StatusText, sizeof(StatusText), "Loading %s", LinuxKernelName);
     UiDrawStatusText(StatusText);
 
     /* Allocate memory for Linux kernel */
@@ -411,7 +411,7 @@ BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile)
     ULONG        BytesLoaded;
     CHAR    StatusText[260];
 
-    sprintf(StatusText, "Loading %s", LinuxInitrdName);
+    RtlStringCbPrintfA(StatusText, sizeof(StatusText), "Loading %s", LinuxInitrdName);
     UiDrawStatusText(StatusText);
 
     // Allocate memory for the ramdisk
index 155030d..3f81381 100644 (file)
@@ -586,15 +586,15 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead,
                     {
                         TRACE_CH(REACTOS, "ImagePath: not found\n");
                         TempImagePath[0] = 0;
-                        sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", DirectoryPath, ServiceName);
+                        RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%s\\system32\\drivers\\%S.sys", DirectoryPath, ServiceName);
                     }
                     else if (TempImagePath[0] != L'\\')
                     {
-                        sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
+                        RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%s%S", DirectoryPath, TempImagePath);
                     }
                     else
                     {
-                        sprintf(ImagePath, "%S", TempImagePath);
+                        RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%S", TempImagePath);
                         TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath);
                     }
 
@@ -666,15 +666,15 @@ WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead,
                 {
                     TRACE_CH(REACTOS, "ImagePath: not found\n");
                     TempImagePath[0] = 0;
-                    sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", DirectoryPath, ServiceName);
+                    RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%ssystem32\\drivers\\%S.sys", DirectoryPath, ServiceName);
                 }
                 else if (TempImagePath[0] != L'\\')
                 {
-                    sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
+                    RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%s%S", DirectoryPath, TempImagePath);
                 }
                 else
                 {
-                    sprintf(ImagePath, "%S", TempImagePath);
+                    RtlStringCbPrintfA(ImagePath, sizeof(ImagePath), "%S", TempImagePath);
                     TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath);
                 }
                 TRACE("  Adding boot driver: '%s'\n", ImagePath);