15
15
#include <linux/errno.h>
16
16
#include <linux/fs.h>
17
17
#include <linux/mutex.h>
18
- #include <linux/string .h>
18
+ #include <linux/string_helpers .h>
19
19
#include <linux/types.h>
20
20
#include <linux/dmi.h>
21
21
#include <linux/wmi.h>
@@ -432,13 +432,11 @@ static ssize_t new_password_store(struct kobject *kobj,
432
432
if (!tlmi_priv .can_set_bios_password )
433
433
return - EOPNOTSUPP ;
434
434
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 );
436
437
if (!new_pwd )
437
438
return - ENOMEM ;
438
439
439
- /* Strip out CR if one is present, setting password won't work if it is present */
440
- strip_cr (new_pwd );
441
-
442
440
/* Use lock in case multiple WMI operations needed */
443
441
mutex_lock (& tlmi_mutex );
444
442
@@ -709,13 +707,11 @@ static ssize_t cert_to_password_store(struct kobject *kobj,
709
707
if (!setting -> signature || !setting -> signature [0 ])
710
708
return - EACCES ;
711
709
712
- passwd = kstrdup (buf , GFP_KERNEL );
710
+ /* Strip out CR if one is present */
711
+ passwd = kstrdup_and_replace (buf , '\n' , '\0' , GFP_KERNEL );
713
712
if (!passwd )
714
713
return - ENOMEM ;
715
714
716
- /* Strip out CR if one is present */
717
- strip_cr (passwd );
718
-
719
715
/* Format: 'Password,Signature' */
720
716
auth_str = kasprintf (GFP_KERNEL , "%s,%s" , passwd , setting -> signature );
721
717
if (!auth_str ) {
@@ -765,11 +761,10 @@ static ssize_t certificate_store(struct kobject *kobj,
765
761
return ret ?: count ;
766
762
}
767
763
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 );
769
766
if (!new_cert )
770
767
return - ENOMEM ;
771
- /* Strip out CR if one is present */
772
- strip_cr (new_cert );
773
768
774
769
if (setting -> cert_installed ) {
775
770
/* Certificate is installed so this is an update */
@@ -817,13 +812,11 @@ static ssize_t signature_store(struct kobject *kobj,
817
812
if (!tlmi_priv .certificate_support )
818
813
return - EOPNOTSUPP ;
819
814
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 );
821
817
if (!new_signature )
822
818
return - ENOMEM ;
823
819
824
- /* Strip out CR if one is present */
825
- strip_cr (new_signature );
826
-
827
820
/* Free any previous signature */
828
821
kfree (setting -> signature );
829
822
setting -> signature = new_signature ;
@@ -846,13 +839,11 @@ static ssize_t save_signature_store(struct kobject *kobj,
846
839
if (!tlmi_priv .certificate_support )
847
840
return - EOPNOTSUPP ;
848
841
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 );
850
844
if (!new_signature )
851
845
return - ENOMEM ;
852
846
853
- /* Strip out CR if one is present */
854
- strip_cr (new_signature );
855
-
856
847
/* Free any previous signature */
857
848
kfree (setting -> save_signature );
858
849
setting -> save_signature = new_signature ;
@@ -992,13 +983,11 @@ static ssize_t current_value_store(struct kobject *kobj,
992
983
if (tlmi_priv .save_mode == TLMI_SAVE_BULK && tlmi_priv .reboot_required )
993
984
return - EPERM ;
994
985
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 );
996
988
if (!new_setting )
997
989
return - ENOMEM ;
998
990
999
- /* Strip out CR if one is present */
1000
- strip_cr (new_setting );
1001
-
1002
991
/* Use lock in case multiple WMI operations needed */
1003
992
mutex_lock (& tlmi_mutex );
1004
993
@@ -1279,13 +1268,11 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
1279
1268
if (!tlmi_priv .can_debug_cmd )
1280
1269
return - EOPNOTSUPP ;
1281
1270
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 );
1283
1273
if (!new_setting )
1284
1274
return - ENOMEM ;
1285
1275
1286
- /* Strip out CR if one is present */
1287
- strip_cr (new_setting );
1288
-
1289
1276
if (tlmi_priv .pwd_admin -> valid && tlmi_priv .pwd_admin -> password [0 ]) {
1290
1277
auth_str = kasprintf (GFP_KERNEL , "%s,%s,%s;" ,
1291
1278
tlmi_priv .pwd_admin -> password ,
0 commit comments