summaryrefslogtreecommitdiffstats
path: root/tools/afcclient.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-06-10 09:43:52 +0200
committerGravatar Nikias Bassen2026-06-10 09:43:52 +0200
commit38a80d7ec157cdf1afb047b6ff99bbfcc166473f (patch)
treed7ab699650483da92955ba985b7fbf8cd2fdce97 /tools/afcclient.c
parent5ca453f9e3950b1f24b51e4cdf255236e34254c4 (diff)
downloadlibimobiledevice-38a80d7ec157cdf1afb047b6ff99bbfcc166473f.tar.gz
libimobiledevice-38a80d7ec157cdf1afb047b6ff99bbfcc166473f.tar.bz2
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.
Diffstat (limited to 'tools/afcclient.c')
-rw-r--r--tools/afcclient.c7
1 files changed, 5 insertions, 2 deletions
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)
332 332
333 for (int i = 0; i < c_count; i++) { 333 for (int i = 0; i < c_count; i++) {
334 if (!strcmp(comps[i].str, "..")) { 334 if (!strcmp(comps[i].str, "..")) {
335 o--; 335 if (o > 1) {
336 o--;
337 }
336 continue; 338 continue;
337 } else if (!strcmp(comps[i].str, ".")) { 339 } else if (!strcmp(comps[i].str, ".")) {
338 continue; 340 continue;
@@ -1202,8 +1204,10 @@ static void handle_cd(afc_client_t afc, int argc, char** argv)
1202 } 1204 }
1203 if (p == curdir) { 1205 if (p == curdir) {
1204 *(p+1) = '\0'; 1206 *(p+1) = '\0';
1207 curdir_len = 1;
1205 } else { 1208 } else {
1206 *p = '\0'; 1209 *p = '\0';
1210 curdir_len = strlen(curdir);
1207 } 1211 }
1208 return; 1212 return;
1209 } 1213 }
@@ -1227,7 +1231,6 @@ static void handle_cd(afc_client_t afc, int argc, char** argv)
1227 free(path); 1231 free(path);
1228 return; 1232 return;
1229 } 1233 }
1230
1231 free(curdir); 1234 free(curdir);
1232 curdir = path; 1235 curdir = path;
1233 curdir_len = strlen(curdir); 1236 curdir_len = strlen(curdir);