platform/x86: think-lmi: Use snprintf() in new_password_store()
Subsystems (3)
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
@@ -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);
Quoted 36 lines · Thorsten Blum
While the current code works correctly, replace unbounded
sprintf()calls with the safersnprintf()innew_password_store()to follow secure coding best practices.Signed-off-by Thorsten Blum <[email protected]>--- drivers/platform/x86/lenovo/think-lmi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/platform/x86/lenovo/think-lmi.c +5
-5@@ -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
Ilpo Järvinen
maintainerQuoted 3 lines · Thorsten Blum
While the current code works correctly, replace unbounded
sprintf()calls with the safersnprintf()innew_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.