From 73080d3a53ecc15bd3e0967857fc7093a10d2c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Tue, 2 Apr 2024 18:57:29 +0200 Subject: [PATCH] Improve buffer overflow checking in scsi_command_util::ModeSelect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Klaus Kämpf --- cpp/devices/scsi_command_util.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cpp/devices/scsi_command_util.cpp b/cpp/devices/scsi_command_util.cpp index f7b31d22..940be2bd 100644 --- a/cpp/devices/scsi_command_util.cpp +++ b/cpp/devices/scsi_command_util.cpp @@ -33,9 +33,17 @@ string scsi_command_util::ModeSelect(scsi_command cmd, cdb_t cdb, span 1 because we access buf[offset+1] below - while (length > 1) { + while (length > 0) { // Format device page if (const int page = buf[offset]; page == 0x03) { if (length < 14) { @@ -68,12 +75,20 @@ string scsi_command_util::ModeSelect(scsi_command cmd, cdb_t cdb, span