Skip to contentSkip to conversation

perf: replace strcpy() with strncpy() in util/jitdump.c

PATCH Applied Hrishikesh Suresh 2 participants 2 messages Nov 20, 2025 – Nov 21, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: replace strcpy() with strncpy() in util/jitdump.c

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

---
 tools/perf/util/jitdump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/jitdump.c +2 -1
index b062b1f234b6..496ca2d2bfdb 100644
@@ -233,7 +233,8 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 	/*
 	 * 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);
 
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 11 lines · Hrishikesh Suresh

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

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung