From ff82d4f82f5bc0126ab57942d956657dca8f88b0 Mon Sep 17 00:00:00 2001 From: oreo639 Date: Sat, 6 May 2023 23:42:00 -0700 Subject: [PATCH] archive_dev: Ensure path seperator for local path Fixes issue where fopen("test.txt","r") opens 3dstest.txt instead of test.txt. Also correct misuse of strncat() as count applies to src not dest. See: https://github.com/devkitPro/3ds-hbmenu/commit/8136d94657dff0075103f0cf36ed5f2d9159e27c https://github.com/devkitPro/newlib/commit/806a4d34c5408d393dbd2b6b9cae22184c57d3a8 --- libctru/source/archive_dev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libctru/source/archive_dev.c b/libctru/source/archive_dev.c index 50a1d6a62..fdc7ef6ba 100644 --- a/libctru/source/archive_dev.c +++ b/libctru/source/archive_dev.c @@ -205,9 +205,11 @@ archive_fixpath(struct _reent *r, strncpy(__ctru_dev_path_buf, path, PATH_MAX); else { - strncpy(__ctru_dev_path_buf, dev->cwd, PATH_MAX); + size_t cwdlen = strlen(dev->cwd); + strncpy(__ctru_dev_path_buf, dev->cwd, PATH_MAX - 1); __ctru_dev_path_buf[PATH_MAX] = '\0'; - strncat(__ctru_dev_path_buf, path, PATH_MAX); + strncat(__ctru_dev_path_buf, "/", PATH_MAX - cwdlen); + strncat(__ctru_dev_path_buf, path, PATH_MAX - cwdlen - 1); } if(__ctru_dev_path_buf[PATH_MAX] != 0)