sumversion: Fix a memory leak in get_src_version()

strsep() modifies its first argument - buf.
An invalid pointer will be passed to the free() function.
Make the pointer passed to free() match the return value of
read_text_file().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 9413e76405 ("kbuild: split the second line of *.mod into *.usyms")
Signed-off-by: Elena Salomatkina <esalomatkina@ispras.ru>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
Elena Salomatkina 2024-10-23 00:37:08 +03:00 committed by Masahiro Yamada
parent 42f7652d3e
commit 4b60a56555

View File

@ -392,7 +392,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
/* Calc and record src checksum. */ /* Calc and record src checksum. */
void get_src_version(const char *modname, char sum[], unsigned sumlen) void get_src_version(const char *modname, char sum[], unsigned sumlen)
{ {
char *buf; char *buf, *pos;
struct md4_ctx md; struct md4_ctx md;
char *fname; char *fname;
char filelist[PATH_MAX + 1]; char filelist[PATH_MAX + 1];
@ -401,9 +401,10 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
snprintf(filelist, sizeof(filelist), "%s.mod", modname); snprintf(filelist, sizeof(filelist), "%s.mod", modname);
buf = read_text_file(filelist); buf = read_text_file(filelist);
pos = buf;
md4_init(&md); md4_init(&md);
while ((fname = strsep(&buf, "\n"))) { while ((fname = strsep(&pos, "\n"))) {
if (!*fname) if (!*fname)
continue; continue;
if (!(is_static_library(fname)) && if (!(is_static_library(fname)) &&