mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
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. Link: https://github.com/KSPP/linux/issues/88 Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Daniel Gomez <da.gomez@samsung.com> Reviewed-by: Petr Pavlu <petr.pavlu@suse.com> Link: https://lore.kernel.org/r/20250813132200.184064-2-thorsten.blum@linux.dev Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
This commit is contained in:
parent
8f5ae30d69
commit
5eb4b9a4cd
@ -513,13 +513,14 @@ EXPORT_SYMBOL(param_array_ops);
|
|||||||
int param_set_copystring(const char *val, const struct kernel_param *kp)
|
int param_set_copystring(const char *val, const struct kernel_param *kp)
|
||||||
{
|
{
|
||||||
const struct kparam_string *kps = kp->str;
|
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",
|
pr_err("%s: string doesn't fit in %u chars.\n",
|
||||||
kp->name, kps->maxlen-1);
|
kp->name, kps->maxlen-1);
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
strcpy(kps->string, val);
|
memcpy(kps->string, val, len + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(param_set_copystring);
|
EXPORT_SYMBOL(param_set_copystring);
|
||||||
@ -841,7 +842,7 @@ static void __init param_sysfs_builtin(void)
|
|||||||
dot = strchr(kp->name, '.');
|
dot = strchr(kp->name, '.');
|
||||||
if (!dot) {
|
if (!dot) {
|
||||||
/* This happens for core_param() */
|
/* This happens for core_param() */
|
||||||
strcpy(modname, "kernel");
|
strscpy(modname, "kernel");
|
||||||
name_len = 0;
|
name_len = 0;
|
||||||
} else {
|
} else {
|
||||||
name_len = dot - kp->name + 1;
|
name_len = dot - kp->name + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user