[PATCH v1 1/4] perf find-map: Remove PATH_MAX 128-byte stack array restriction

From: Ian Rogers

Date: Mon Jul 20 2026 - 14:07:00 EST


Use getline() to dynamically allocate the required line buffer for maps
parsing, guaranteeing bounds safety and preventing buffer overruns.

Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/find-map.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/find-map.c b/tools/perf/util/find-map.c
index 7b2300588ece..4d740b32814f 100644
--- a/tools/perf/util/find-map.c
+++ b/tools/perf/util/find-map.c
@@ -1,8 +1,14 @@
// 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;
+ ssize_t read_ret;
int found = 0;

maps = fopen("/proc/self/maps", "r");
@@ -11,7 +17,7 @@ static int find_map(void **start, void **end, const char *name)
return -1;
}

- while (!found && fgets(line, sizeof(line), maps)) {
+ while (!found && (read_ret = getline(&line, &len, maps)) != -1) {
int m = -1;

/* We care only about private r-x mappings. */
@@ -25,6 +31,7 @@ static int find_map(void **start, void **end, const char *name)
found = 1;
}

+ free(line);
fclose(maps);
return !found;
}
--
2.55.0.229.g6434b31f56-goog