1515#include <linux/errno.h>
1616#include <linux/fs.h>
1717#include <linux/mutex.h>
18- #include <linux/string .h>
18+ #include <linux/string_helpers .h>
1919#include <linux/types.h>
2020#include <linux/dmi.h>
2121#include <linux/wmi.h>
@@ -432,13 +432,11 @@ static ssize_t new_password_store(struct kobject *kobj,
432432 if (!tlmi_priv .can_set_bios_password )
433433 return - EOPNOTSUPP ;
434434
435- new_pwd = kstrdup (buf , GFP_KERNEL );
435+ /* Strip out CR if one is present, setting password won't work if it is present */
436+ new_pwd = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
436437 if (!new_pwd )
437438 return - ENOMEM ;
438439
439- /* Strip out CR if one is present, setting password won't work if it is present */
440- strip_cr (new_pwd );
441-
442440 /* Use lock in case multiple WMI operations needed */
443441 mutex_lock (& tlmi_mutex );
444442
@@ -709,13 +707,11 @@ static ssize_t cert_to_password_store(struct kobject *kobj,
709707 if (!setting -> signature || !setting -> signature [0 ])
710708 return - EACCES ;
711709
712- passwd = kstrdup (buf , GFP_KERNEL );
710+ /* Strip out CR if one is present */
711+ passwd = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
713712 if (!passwd )
714713 return - ENOMEM ;
715714
716- /* Strip out CR if one is present */
717- strip_cr (passwd );
718-
719715 /* Format: 'Password,Signature' */
720716 auth_str = kasprintf (GFP_KERNEL , "%s,%s" , passwd , setting -> signature );
721717 if (!auth_str ) {
@@ -765,11 +761,10 @@ static ssize_t certificate_store(struct kobject *kobj,
765761 return ret ?: count ;
766762 }
767763
768- new_cert = kstrdup (buf , GFP_KERNEL );
764+ /* Strip out CR if one is present */
765+ new_cert = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
769766 if (!new_cert )
770767 return - ENOMEM ;
771- /* Strip out CR if one is present */
772- strip_cr (new_cert );
773768
774769 if (setting -> cert_installed ) {
775770 /* Certificate is installed so this is an update */
@@ -817,13 +812,11 @@ static ssize_t signature_store(struct kobject *kobj,
817812 if (!tlmi_priv .certificate_support )
818813 return - EOPNOTSUPP ;
819814
820- new_signature = kstrdup (buf , GFP_KERNEL );
815+ /* Strip out CR if one is present */
816+ new_signature = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
821817 if (!new_signature )
822818 return - ENOMEM ;
823819
824- /* Strip out CR if one is present */
825- strip_cr (new_signature );
826-
827820 /* Free any previous signature */
828821 kfree (setting -> signature );
829822 setting -> signature = new_signature ;
@@ -846,13 +839,11 @@ static ssize_t save_signature_store(struct kobject *kobj,
846839 if (!tlmi_priv .certificate_support )
847840 return - EOPNOTSUPP ;
848841
849- new_signature = kstrdup (buf , GFP_KERNEL );
842+ /* Strip out CR if one is present */
843+ new_signature = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
850844 if (!new_signature )
851845 return - ENOMEM ;
852846
853- /* Strip out CR if one is present */
854- strip_cr (new_signature );
855-
856847 /* Free any previous signature */
857848 kfree (setting -> save_signature );
858849 setting -> save_signature = new_signature ;
@@ -992,13 +983,11 @@ static ssize_t current_value_store(struct kobject *kobj,
992983 if (tlmi_priv .save_mode == TLMI_SAVE_BULK && tlmi_priv .reboot_required )
993984 return - EPERM ;
994985
995- new_setting = kstrdup (buf , GFP_KERNEL );
986+ /* Strip out CR if one is present */
987+ new_setting = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
996988 if (!new_setting )
997989 return - ENOMEM ;
998990
999- /* Strip out CR if one is present */
1000- strip_cr (new_setting );
1001-
1002991 /* Use lock in case multiple WMI operations needed */
1003992 mutex_lock (& tlmi_mutex );
1004993
@@ -1279,13 +1268,11 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
12791268 if (!tlmi_priv .can_debug_cmd )
12801269 return - EOPNOTSUPP ;
12811270
1282- new_setting = kstrdup (buf , GFP_KERNEL );
1271+ /* Strip out CR if one is present */
1272+ new_setting = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
12831273 if (!new_setting )
12841274 return - ENOMEM ;
12851275
1286- /* Strip out CR if one is present */
1287- strip_cr (new_setting );
1288-
12891276 if (tlmi_priv .pwd_admin -> valid && tlmi_priv .pwd_admin -> password [0 ]) {
12901277 auth_str = kasprintf (GFP_KERNEL , "%s,%s,%s;" ,
12911278 tlmi_priv .pwd_admin -> password ,
0 commit comments