From 38a80d7ec157cdf1afb047b6ff99bbfcc166473f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 10 Jun 2026 09:43:52 +0200 Subject: tools/afcclient: Fix `cd` handling code Not all path would update curdir_len, which resulted in copying too many or not enough bytes when changing the directory. --- tools/afcclient.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tools/afcclient.c') diff --git a/tools/afcclient.c b/tools/afcclient.c index 2667e52..e71aea4 100644 --- a/tools/afcclient.c +++ b/tools/afcclient.c @@ -332,7 +332,9 @@ static char* get_realpath(const char* path) for (int i = 0; i < c_count; i++) { if (!strcmp(comps[i].str, "..")) { - o--; + if (o > 1) { + o--; + } continue; } else if (!strcmp(comps[i].str, ".")) { continue; @@ -1202,8 +1204,10 @@ static void handle_cd(afc_client_t afc, int argc, char** argv) } if (p == curdir) { *(p+1) = '\0'; + curdir_len = 1; } else { *p = '\0'; + curdir_len = strlen(curdir); } return; } @@ -1227,7 +1231,6 @@ static void handle_cd(afc_client_t afc, int argc, char** argv) free(path); return; } - free(curdir); curdir = path; curdir_len = strlen(curdir); -- cgit v1.1-32-gdbae