Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 9413e7640564 ("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>

authored by

Elena Salomatkina and committed by
Masahiro Yamada
4b60a565 42f7652d

+3 -2
+3 -2
scripts/mod/sumversion.c
··· 392 392 /* Calc and record src checksum. */ 393 393 void get_src_version(const char *modname, char sum[], unsigned sumlen) 394 394 { 395 - char *buf; 395 + char *buf, *pos; 396 396 struct md4_ctx md; 397 397 char *fname; 398 398 char filelist[PATH_MAX + 1]; ··· 401 401 snprintf(filelist, sizeof(filelist), "%s.mod", modname); 402 402 403 403 buf = read_text_file(filelist); 404 + pos = buf; 404 405 405 406 md4_init(&md); 406 - while ((fname = strsep(&buf, "\n"))) { 407 + while ((fname = strsep(&pos, "\n"))) { 407 408 if (!*fname) 408 409 continue; 409 410 if (!(is_static_library(fname)) &&