From 8872902990359ee9ffabe576016201a1c934d453 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 9 Dec 2025 21:15:48 +0100 Subject: [PATCH] strcpy Without Bounds Checking --- src/printer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index a0313ef..59ea30f 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -44,10 +44,10 @@ void Printer::print(Drive *drive) snprintf(msgQueueData.driveData.caDriveIndex, STR_BUFFER_SIZE, "%i", drive->u16DriveIndex); snprintf(msgQueueData.driveData.caDriveState, STR_BUFFER_SIZE, "shredded"); - strcpy(msgQueueData.driveData.caDriveModelFamily, drive->getModelFamily().c_str()); - strcpy(msgQueueData.driveData.caDriveModelName, drive->getModelName().c_str()); + snprintf(msgQueueData.driveData.caDriveModelFamily, STR_BUFFER_SIZE, "%s", drive->getModelFamily().c_str()); + snprintf(msgQueueData.driveData.caDriveModelName, STR_BUFFER_SIZE, "%s", drive->getModelName().c_str()); snprintf(msgQueueData.driveData.caDriveCapacity, STR_BUFFER_SIZE, "%li", drive->getCapacity()); - strcpy(msgQueueData.driveData.caDriveSerialnumber, drive->getSerial().c_str()); + snprintf(msgQueueData.driveData.caDriveSerialnumber, STR_BUFFER_SIZE, "%s", drive->getSerial().c_str()); snprintf(msgQueueData.driveData.caDriveHours, STR_BUFFER_SIZE, "%i", drive->getPowerOnHours()); snprintf(msgQueueData.driveData.caDriveCycles, STR_BUFFER_SIZE, "%i", drive->getPowerCycles()); snprintf(msgQueueData.driveData.caDriveErrors, STR_BUFFER_SIZE, "%i", drive->getErrorCount()); @@ -57,17 +57,17 @@ void Printer::print(Drive *drive) switch (drive->connectionType) { case Drive::USB: - strcpy(msgQueueData.driveData.caDriveConnectionType, "usb"); + strncpy(msgQueueData.driveData.caDriveConnectionType, "usb", STR_BUFFER_SIZE); break; case Drive::SATA: - strcpy(msgQueueData.driveData.caDriveConnectionType, "sata"); + strncpy(msgQueueData.driveData.caDriveConnectionType, "sata", STR_BUFFER_SIZE); break; case Drive::NVME: - strcpy(msgQueueData.driveData.caDriveConnectionType, "nvme"); + strncpy(msgQueueData.driveData.caDriveConnectionType, "nvme", STR_BUFFER_SIZE); break; case Drive::UNKNOWN: default: - strcpy(msgQueueData.driveData.caDriveConnectionType, "na"); + strncpy(msgQueueData.driveData.caDriveConnectionType, "na", STR_BUFFER_SIZE); } snprintf(msgQueueData.driveData.caDriveReHddVersion, STR_BUFFER_SIZE, "%s", REHDD_VERSION);