Skip to content

Commit f4940ab

Browse files
Chen Gangrustyrussell
authored andcommitted
kernel/params.c: use scnprintf() instead of sprintf()
For some strings (e.g. version string), they are permitted to be larger than PAGE_SIZE (although meaningless), so recommend to use scnprintf() instead of sprintf(). Signed-off-by: Chen Gang <gang.chen@asianux.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent cc56ded commit f4940ab

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎kernel/params.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ int parse_args(const char *doing,
241241
} \
242242
int param_get_##name(char *buffer, const struct kernel_param *kp) \
243243
{ \
244-
return sprintf(buffer, format, *((type *)kp->arg)); \
244+
return scnprintf(buffer, PAGE_SIZE, format, \
245+
*((type *)kp->arg)); \
245246
} \
246247
struct kernel_param_ops param_ops_##name = { \
247248
.set = param_set_##name, \
@@ -285,7 +286,7 @@ EXPORT_SYMBOL(param_set_charp);
285286

286287
int param_get_charp(char *buffer, const struct kernel_param *kp)
287288
{
288-
return sprintf(buffer, "%s", *((char **)kp->arg));
289+
return scnprintf(buffer, PAGE_SIZE, "%s", *((char **)kp->arg));
289290
}
290291
EXPORT_SYMBOL(param_get_charp);
291292

@@ -829,7 +830,7 @@ ssize_t __modver_version_show(struct module_attribute *mattr,
829830
struct module_version_attribute *vattr =
830831
container_of(mattr, struct module_version_attribute, mattr);
831832

832-
return sprintf(buf, "%s\n", vattr->version);
833+
return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
833834
}
834835

835836
extern const struct module_version_attribute *__start___modver[];

0 commit comments

Comments
 (0)