From 7aff21e3a9471f7653d66a1e0fc736657bcea255 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 16 Jul 2026 22:37:40 +0200 Subject: [PATCH] Fix wide-character buffer size parameters in mingwapp.c snwprintf calls to prevent stack buffer overflow --- cmdline/mingwapp.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmdline/mingwapp.c b/cmdline/mingwapp.c index daa68396..28a4bace 100644 --- a/cmdline/mingwapp.c +++ b/cmdline/mingwapp.c @@ -898,9 +898,9 @@ static int devsmart(uint64_t device, const char* name, const char* smartctl, con if (smartctl[0]) { char option[SMART_MAX]; snprintf(option, sizeof(option), smartctl, file); - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" %s %s", windows_exedir(), info_opts, option); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" %s %s", windows_exedir(), info_opts, option); } else { - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" %s %s", windows_exedir(), info_opts, file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" %s %s", windows_exedir(), info_opts, file); } count = 0; @@ -956,7 +956,7 @@ retry: && info[INFO_ROTATION_RATE] == SMART_UNASSIGNED ) { /* retry using the "sat" type */ - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" %s -d sat %s", windows_exedir(), info_opts, file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" %s -d sat %s", windows_exedir(), info_opts, file); ++count; goto retry; @@ -1222,9 +1222,9 @@ static int devprobe(uint64_t device, const char* name, const char* smartctl, con if (smartctl[0]) { char option[SMART_MAX]; snprintf(option, sizeof(option), smartctl, file); - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -n standby,3 %s %s", windows_exedir(), info_opts, option); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -n standby,3 %s %s", windows_exedir(), info_opts, option); } else { - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -n standby,3 %s %s", windows_exedir(), info_opts, file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -n standby,3 %s %s", windows_exedir(), info_opts, file); } count = 0; @@ -1273,7 +1273,7 @@ retry: */ if (ret == 2) { /* retry using the "sat" type */ - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -n standby,3 %s -d sat %s", windows_exedir(), info_opts, file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -n standby,3 %s -d sat %s", windows_exedir(), info_opts, file); ++count; goto retry; @@ -1313,9 +1313,9 @@ static int devdown(uint64_t device, const char* name, const char* smartctl) if (smartctl[0]) { char option[SMART_MAX]; snprintf(option, sizeof(option), smartctl, file); - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -s standby,now %s", windows_exedir(), option); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -s standby,now %s", windows_exedir(), option); } else { - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -s standby,now %s", windows_exedir(), file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -s standby,now %s", windows_exedir(), file); } count = 0; @@ -1364,7 +1364,7 @@ retry: */ if (ret == 2) { /* retry using the "sat" type */ - snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -s standby,now -d sat %s", windows_exedir(), file); + snwprintf(cmd, sizeof(cmd) / sizeof(cmd[0]), L"\"%lssmartctl.exe\" -s standby,now -d sat %s", windows_exedir(), file); ++count; goto retry;