Skip to content

Commit 4b60a56

Browse files
Elena Salomatkinamasahir0y
authored andcommitted
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: 9413e76 ("kbuild: split the second line of *.mod into *.usyms") Signed-off-by: Elena Salomatkina <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 42f7652 commit 4b60a56

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scripts/mod/sumversion.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
392392
/* Calc and record src checksum. */
393393
void get_src_version(const char *modname, char sum[], unsigned sumlen)
394394
{
395-
char *buf;
395+
char *buf, *pos;
396396
struct md4_ctx md;
397397
char *fname;
398398
char filelist[PATH_MAX + 1];
@@ -401,9 +401,10 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
401401
snprintf(filelist, sizeof(filelist), "%s.mod", modname);
402402

403403
buf = read_text_file(filelist);
404+
pos = buf;
404405

405406
md4_init(&md);
406-
while ((fname = strsep(&buf, "\n"))) {
407+
while ((fname = strsep(&pos, "\n"))) {
407408
if (!*fname)
408409
continue;
409410
if (!(is_static_library(fname)) &&

0 commit comments

Comments
 (0)