mirror of
https://github.com/torvalds/linux.git
synced 2024-11-12 23:23:03 +00:00
modpost: use snprintf() instead of sprintf() for safety
Use snprintf() to avoid the potential buffer overflow, and also check the return value to detect the too long path. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
This commit is contained in:
parent
f4d40868fc
commit
15a28c7c72
@ -2560,6 +2560,7 @@ int main(int argc, char **argv)
|
||||
|
||||
for (mod = modules; mod; mod = mod->next) {
|
||||
char fname[PATH_MAX];
|
||||
int ret;
|
||||
|
||||
if (mod->is_vmlinux || mod->from_dump)
|
||||
continue;
|
||||
@ -2578,7 +2579,12 @@ int main(int argc, char **argv)
|
||||
add_moddevtable(&buf, mod);
|
||||
add_srcversion(&buf, mod);
|
||||
|
||||
sprintf(fname, "%s.mod.c", mod->name);
|
||||
ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
|
||||
if (ret >= sizeof(fname)) {
|
||||
error("%s: too long path was truncated\n", fname);
|
||||
continue;
|
||||
}
|
||||
|
||||
write_if_changed(&buf, fname);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user