From: Masahiro Yamada masahiroy@kernel.org
mainline inclusion from mainline-5.8 commit 70f30cfe5b892fcb7f98e7df72ed6ccfe3225628 category: bugfix bugzilla: 46847 CVE: NA
------------------------------------------------
grab_file() mmaps a file, but it is not so efficient here because get_next_line() copies every line to the temporary buffer anyway.
read_text_file() and get_line() are simpler. get_line() exploits the library function strchr().
Going forward, the missing *.symvers or *.cmd is a fatal error. This should not happen because scripts/Makefile.modpost guards the -i option files with $(wildcard $(input-symdump)).
Signed-off-by: Masahiro Yamada masahiroy@kernel.org
Drop the changes in modpost.c since the missing *.symvers or *.cmd is a fatal error and we don't check it in scripts/Makefile.modpost currently, on which curimistance the building process for modules would be interrupted with an error. This isn't what we expect.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com Reviewed-by: Jian Cheng cj.chengjian@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- scripts/mod/sumversion.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c index 0f6dcb4011a8..b7b52350d08e 100644 --- a/scripts/mod/sumversion.c +++ b/scripts/mod/sumversion.c @@ -304,9 +304,8 @@ static int is_static_library(const char *objfile) * to figure out source files. */ static int parse_source_files(const char *objfile, struct md4_ctx *md) { - char *cmd, *file, *line, *dir; + char *cmd, *file, *line, *dir, *pos; const char *base; - unsigned long flen, pos = 0; int dirlen, ret = 0, check_files = 0;
cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); @@ -324,14 +323,12 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) strncpy(dir, objfile, dirlen); dir[dirlen] = '\0';
- file = grab_file(cmd, &flen); - if (!file) { - warn("could not find %s for %s\n", cmd, objfile); - goto out; - } + file = read_text_file(cmd); + + pos = file;
/* Sum all files in the same dir or subdirs. */ - while ((line = get_next_line(&pos, file, flen)) != NULL) { + while ((line = get_line(&pos))) { char* p = line;
if (strncmp(line, "source_", sizeof("source_")-1) == 0) { @@ -382,8 +379,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md) /* Everyone parsed OK */ ret = 1; out_file: - release_file(file, flen); -out: + free(file); free(dir); free(cmd); return ret;