Skip to contentSkip to conversation

platform/x86: think-lmi: Use snprintf() in new_password_store()

PATCH In review Thorsten Blum 3 participants 3 messages Sep 20 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: think-lmi: Use snprintf() in new_password_store()

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

---
 drivers/platform/x86/lenovo/think-lmi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/platform/x86/lenovo/think-lmi.c +5 -5
index a0e3fa766e37..3ddc1f5cec19 100644
@@ -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);
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 36 lines · Thorsten Blum

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

---
 drivers/platform/x86/lenovo/think-lmi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/platform/x86/lenovo/think-lmi.c +5 -5
index a0e3fa766e37..3ddc1f5cec19 100644
@@ -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);
 		}
 
Quoted 1 line

ret = tlmi_opcode_setting("WmiOpcodePasswordType", pwd_type);

Mark

maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 3 lines · Thorsten Blum

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

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.

The list of commits applied:
[1/1] platform/x86: think-lmi: Use snprintf() in new_password_store()

      commit: ff29048d56ed5069c5dfcb192a5b0687d3f45869

--
i.