summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-07-21 16:52:50 -0700
committerNamhyung Kim <namhyung@kernel.org>2026-08-07 09:43:36 -0700
commite46a9b8150c9cd7a41ae963389901a85ec40bea8 (patch)
tree2ef0fb2cc403cbade409ae61d4de7a75cf02766c /tools
parent43a163494ff7aee0c8add586e54db4f1d706bf4e (diff)
perf find-map: Remove PATH_MAX 128-byte stack array restriction
Use getline() to dynamically allocate the required line buffer for maps parsing, guaranteeing bounds safety and avoiding compiler warnings by evaluating the return value in the loop condition directly. Assisted-by: Antigravity:gemini-3.5-flash Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/find-map.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/perf/util/find-map.c b/tools/perf/util/find-map.c
index 7b2300588ece..bba511795a69 100644
--- a/tools/perf/util/find-map.c
+++ b/tools/perf/util/find-map.c
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
static int find_map(void **start, void **end, const char *name)
{
FILE *maps;
- char line[128];
+ char *line = NULL;
+ size_t len = 0;
int found = 0;
maps = fopen("/proc/self/maps", "r");
@@ -11,7 +16,7 @@ static int find_map(void **start, void **end, const char *name)
return -1;
}
- while (!found && fgets(line, sizeof(line), maps)) {
+ while (!found && getline(&line, &len, maps) != -1) {
int m = -1;
/* We care only about private r-x mappings. */
@@ -25,6 +30,7 @@ static int find_map(void **start, void **end, const char *name)
found = 1;
}
+ free(line);
fclose(maps);
return !found;
}