https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8f050e66fd51d2d035815…
commit 8f050e66fd51d2d03581558f26b6a6501c4c588b
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sun Apr 28 17:48:58 2019 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Jul 20 13:56:18 2019 +0200
[FREELDR] Use RtlStringCbPrintfA instead of sprintf
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 | 9 ++++++---
boot/freeldr/freeldr/include/freeldr.h | 1 +
boot/freeldr/freeldr/linuxboot.c | 4 ++--
boot/freeldr/freeldr/ntldr/wlregistry.c | 12 ++++++------
4 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/boot/freeldr/freeldr/disk/scsiport.c b/boot/freeldr/freeldr/disk/scsiport.c
index 7f206aafe65..0c0a0fa66cc 100644
--- a/boot/freeldr/freeldr/disk/scsiport.c
+++ b/boot/freeldr/freeldr/disk/scsiport.c
@@ -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);
}
}
diff --git a/boot/freeldr/freeldr/include/freeldr.h
b/boot/freeldr/freeldr/include/freeldr.h
index b62d4e56003..82a6b89f06b 100644
--- a/boot/freeldr/freeldr/include/freeldr.h
+++ b/boot/freeldr/freeldr/include/freeldr.h
@@ -50,6 +50,7 @@
#include <internal/hal.h>
#include <drivers/pci/pci.h>
#include <winerror.h>
+#include <ntstrsafe.h>
#else
#include <ntsup.h>
#endif
diff --git a/boot/freeldr/freeldr/linuxboot.c b/boot/freeldr/freeldr/linuxboot.c
index 54b16a62827..23258941eb8 100644
--- a/boot/freeldr/freeldr/linuxboot.c
+++ b/boot/freeldr/freeldr/linuxboot.c
@@ -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
diff --git a/boot/freeldr/freeldr/ntldr/wlregistry.c
b/boot/freeldr/freeldr/ntldr/wlregistry.c
index 155030dbc2d..3f813819dfc 100644
--- a/boot/freeldr/freeldr/ntldr/wlregistry.c
+++ b/boot/freeldr/freeldr/ntldr/wlregistry.c
@@ -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);