]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
parse: Fix out of bound access
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 29 Nov 2022 13:28:08 +0000 (15:28 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 29 Nov 2022 13:28:08 +0000 (15:28 +0200)
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 <timo.t.kokkonen@iki.fi>
parse.c

diff --git a/parse.c b/parse.c
index 296d2017f341c7ec134ef2fc6ab1902a77fbea4a..0c9ac14ce5a5ba2463ca1327b1bde1f774f0fd6d 100644 (file)
--- 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';