mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86: think-lmi: Use snprintf() in new_password_store()
@ 2026-09-20 10:30 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-09-20 10:30 UTC (permalink / raw)
  To: Mark Pearson, Derek J. Clark, Hans de Goede, Ilpo Järvinen
  Cc: Thorsten Blum, platform-driver-x86, linux-kernel

While the current code works correctly, replace unbounded sprintf()
calls with the safer snprintf() in new_password_store() to follow secure
coding best practices.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/platform/x86/lenovo/think-lmi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index a0e3fa766e37..3ddc1f5cec19 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -487,16 +487,16 @@ static ssize_t new_password_store(struct kobject *kobj,
 		/* Special handling required for HDD and NVMe passwords */
 		if (setting == tlmi_priv.pwd_hdd) {
 			if (setting->level == TLMI_LEVEL_USER)
-				sprintf(pwd_type, "uhdp%d", setting->index);
+				snprintf(pwd_type, sizeof(pwd_type), "uhdp%d", setting->index);
 			else
-				sprintf(pwd_type, "mhdp%d", setting->index);
+				snprintf(pwd_type, sizeof(pwd_type), "mhdp%d", setting->index);
 		} else if (setting == tlmi_priv.pwd_nvme) {
 			if (setting->level == TLMI_LEVEL_USER)
-				sprintf(pwd_type, "udrp%d", setting->index);
+				snprintf(pwd_type, sizeof(pwd_type), "udrp%d", setting->index);
 			else
-				sprintf(pwd_type, "adrp%d", setting->index);
+				snprintf(pwd_type, sizeof(pwd_type), "adrp%d", setting->index);
 		} else {
-			sprintf(pwd_type, "%s", setting->pwd_type);
+			snprintf(pwd_type, sizeof(pwd_type), "%s", setting->pwd_type);
 		}
 
 		ret = tlmi_opcode_setting("WmiOpcodePasswordType", pwd_type);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-20 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 10:30 [PATCH] platform/x86: think-lmi: Use snprintf() in new_password_store() Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®