Usage of strcpy() can lead to buffer overflows. Therefore, it has been
replaced with strncpy(). The output file path is provided as a parameter
and might be restricted by command-line by default. But this defensive
patch will prevent any potential overflow, making the code more robust
against future changes in input handling.
Testing:
- ran perf test from tools/perf and did not observe any regression with
the earlier code
Signed-off-by: Hrishikesh Suresh <hrishikesh123s@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
/*
* keep dirname for generating files and mmap records
*/
- strcpy(jd->dir, name);
+ strncpy(jd->dir, name, PATH_MAX);
+ jd->dir[PATH_MAX - 1] = '\0';
dirname(jd->dir);
free(buf);