From 3acd6a8b604d97b3269c0f1c81fe61860b27226c Mon Sep 17 00:00:00 2001 From: Martin Lundh Date: Thu, 25 Feb 2021 10:22:50 +0100 Subject: [PATCH] Fixed buffer overrun issue detected by address sanitizer. --- src/complete.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/complete.c b/src/complete.c index d6b8a4b..d78406e 100644 --- a/src/complete.c +++ b/src/complete.c @@ -197,14 +197,14 @@ char *el_filename_complete(char *pathname, int *match) if (ac == 1) { /* Exactly one match -- finish it off. */ *match = 1; - j = strlen(av[0]) - len + 2; - p = malloc(sizeof(char) * (j + 1)); + j = strlen(av[0]) - len + 1; + p = malloc(sizeof(char) * (j + 1)); if (p) { memcpy(p, av[0] + len, j); - len = strlen(dir) + strlen(av[0]) + 2; - path = malloc(sizeof(char) * len); + len = strlen(dir) + strlen(av[0]) + 2; + path = malloc(sizeof(char) * len); if (path) { - snprintf(path, len, "%s/%s", dir, av[0]); + snprintf(path, len, "%s/%s", dir, av[0]); rl_add_slash(path, p); free(path); }