From 692443c49eae3e9409d566fc1f10cd6c3da2ca05 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 29 Nov 2022 15:28:08 +0200 Subject: [PATCH] parse: Fix out of bound access Make sure the copy length is at least one shorter than the buffer size. This isn't strictly required as we would be forcefully NULL terminating the string aynway, but this silences the compiler warning we are getting with modern versions of gcc. Signed-off-by: Timo Kokkonen --- parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse.c b/parse.c index 296d201..0c9ac14 100644 --- a/parse.c +++ b/parse.c @@ -83,7 +83,7 @@ static struct maps *parse_maps(FILE *file, int pid, int tid) map->pid = pid; map->tid = tid; - strncpy(map->name, line + skip, sizeof(map->name)); + strncpy(map->name, line + skip, sizeof(map->name) - 1); /* zero out the newline */ map->name[MAX(strlen(map->name) - 1, 0)] = '\0'; -- 2.45.0