summaryrefslogtreecommitdiffstats
path: root/scripts/mod
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2022-04-24 21:07:45 +0200
committerMasahiro Yamada <masahiroy@kernel.org>2022-05-07 20:16:59 +0200
commit15a28c7c72917f96820e9e9ccd113606363ba3ac (patch)
tree491b81b105d4a0fad6acf8fc1aea033530302973 /scripts/mod
parentchecksyscalls: ignore -Wunused-macros (diff)
downloadlinux-15a28c7c72917f96820e9e9ccd113606363ba3ac.tar.xz
linux-15a28c7c72917f96820e9e9ccd113606363ba3ac.zip
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>
Diffstat (limited to 'scripts/mod')
-rw-r--r--scripts/mod/modpost.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 522d5249d196..141370ebbfd3 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -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);
}