params: Replace deprecated strcpy() with strscpy() and memcpy()
PATCH v2 1/1 params: Replace deprecated strcpy() with strscpy() and memcpy()
strcpy() is deprecated; use strscpy() and memcpy() instead.
In param_set_copystring(), we can safely use memcpy() because we already know the length of the source string 'val' and that it is guaranteed to be NUL-terminated within the first 'kps->maxlen' bytes.
---
Changes in v2:
- Use memcpy() in param_set_copystring() as suggested by Petr Pavlu
- Link to v1: https://lore.kernel.org/lkml/[email protected]/
--- kernel/params.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/params.c +4 -3
@@ -513,13 +513,14 @@ EXPORT_SYMBOL(param_array_ops);int param_set_copystring (const char *val,const struct kernel_param *kp) {const struct kparam_string *kps = kp->str; +const size_t len =strnlen (val, kps->maxlen); -if (strnlen (val, kps->maxlen) == kps->maxlen) { +if (len == kps->maxlen) {pr_err ("%s: string doesn't fit in %u chars.\n" , kp->name, kps->maxlen-1 );return -ENOSPC ; } -strcpy (kps->string, val); +memcpy (kps->string, val, len +1 );return 0 ; }EXPORT_SYMBOL (param_set_copystring);
@@ -841,7 +842,7 @@ static void __init param_sysfs_builtin(void) dot =strchr (kp->name,'.' );if (!dot) {/* This happens for core_param() */ -strcpy (modname,"kernel" ); +strscpy (modname,"kernel" ); name_len =0 ; }else { name_len = dot - kp->name +1 ;
Signature · 1 line
2.50.1
Quoted 38 lines · Thorsten Blum
strcpy()is deprecated; usestrscpy()andmemcpy()instead.In
param_set_copystring(), we can safely usememcpy()because we already know the length of the source string 'val' and that it is guaranteed to be NUL-terminated within the first 'kps->maxlen' bytes.Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Usememcpy()inparam_set_copystring()as suggested by Petr Pavlu
- Link to v1: https://lore.kernel.org/lkml/[email protected]/--- kernel/params.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/params.c +3
-2@@ -513,13 +513,14 @@ EXPORT_SYMBOL(param_array_ops);int param_set_copystring (const char *val,const struct kernel_param *kp) {const struct kparam_string *kps = kp->str; +const size_t len =strnlen (val, kps->maxlen); -if (strnlen (val, kps->maxlen) == kps->maxlen) { +if (len == kps->maxlen) {pr_err ("%s: string doesn't fit in %u chars.\n" , kp->name, kps->maxlen-1 );return -ENOSPC ; } -strcpy (kps->string, val); +memcpy (kps->string, val, len +1 );return 0 ; }EXPORT_SYMBOL (param_set_copystring);
kernel/params.c static void __init param_sysfs_builtin(void) · line 848
Quoted 8 lines
kernel/params.c +1
-1@@ -841,7 +842,7 @@ static void __init param_sysfs_builtin(void) dot =strchr (kp->name,'.' );if (!dot) {/* This happens for core_param() */ -strcpy (modname,"kernel" ); +strscpy (modname,"kernel" ); name_len =0 ; }else { name_len = dot - kp->name +1 ;
Signature · 2 lines
Thanks, Petr
Daniel Gomez
Reviewed-byQuoted 41 lines · Petr Pavlu
Quoted 40 lines · Thorsten Blum
strcpy()is deprecated; usestrscpy()andmemcpy()instead.In
param_set_copystring(), we can safely usememcpy()because we already know the length of the source string 'val' and that it is guaranteed to be NUL-terminated within the first 'kps->maxlen' bytes.Signed-off-by Thorsten Blum <[email protected]>---
Changes in v2:
- Usememcpy()inparam_set_copystring()as suggested by Petr Pavlu
- Link to v1: https://lore.kernel.org/lkml/[email protected]/--- kernel/params.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/params.c +3
-2@@ -513,13 +513,14 @@ EXPORT_SYMBOL(param_array_ops);int param_set_copystring (const char *val,const struct kernel_param *kp) {const struct kparam_string *kps = kp->str; +const size_t len =strnlen (val, kps->maxlen); -if (strnlen (val, kps->maxlen) == kps->maxlen) { +if (len == kps->maxlen) {pr_err ("%s: string doesn't fit in %u chars.\n" , kp->name, kps->maxlen-1 );return -ENOSPC ; } -strcpy (kps->string, val); +memcpy (kps->string, val, len +1 );return 0 ; }EXPORT_SYMBOL (param_set_copystring);@@ -841,7 +842,7 @@ static void __init param_sysfs_builtin(void) dot =strchr (kp->name,'.' );if (!dot) {
Quoted 9 lines
kernel/params.c static void __init param_sysfs_builtin(void) · line 848
Quoted 6 lines
kernel/params.c +1
-1/* This happens for core_param() */ -strcpy (modname,"kernel" ); +strscpy (modname,"kernel" ); name_len =0 ; }else { name_len = dot - kp->name +1 ;Reviewed-by Petr Pavlu <[email protected]>
Daniel Gomez
AppliedQuoted 8 lines · Thorsten Blum
strcpy()is deprecated; usestrscpy()andmemcpy()instead.In
param_set_copystring(), we can safely usememcpy()because we already know the length of the source string 'val' and that it is guaranteed to be NUL-terminated within the first 'kps->maxlen' bytes.[...]
Applied, thanks!
[1/1] params: Replace deprecated strcpy() with strscpy() and memcpy()
commit: 5eb4b9a4cdbb70d70377fe8fb2920b75910e5024
Best regards,
Signature · 1 line
Daniel Gomez <[email protected]>