From 2da3eb1c9cfbd3a5048910b19d6e6e5389fc8eaa Mon Sep 17 00:00:00 2001 From: Adithya <91655764+Pineapple-Soup@users.noreply.github.com> Date: Tue, 5 Aug 2025 19:09:23 +0000 Subject: [PATCH] fix: off-by-one error in `convertPathnameToDirName` --- programs/util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/util.c b/programs/util.c index 652530b1223..78299b01c13 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1148,11 +1148,11 @@ static void convertPathnameToDirName(char *pathname) /* remove trailing '/' chars */ len = strlen(pathname); assert(len > 0); - while (pathname[len] == PATH_SEP) { - pathname[len] = '\0'; + while (pathname[len-1] == PATH_SEP) { + pathname[len-1] = '\0'; len--; + if (len == 0) return; } - if (len == 0) return; /* if input is a single file, return '.' instead. i.e. * "xyz/abc/file.txt" => "xyz/abc"