diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index be7d5ed..7ed79ee 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -651,7 +651,7 @@ u32 ShowFileScrollPrompt(u32 n, const DirEntry** options, bool hide_ext, const c char content_str[64 + 1]; char temp_str[256]; - strncpy(temp_str, options[i]->name, 255); + strncpy(temp_str, options[i]->name, 256); char* dot = strrchr(temp_str, '.'); if (hide_ext && dot) *dot = '\0'; diff --git a/arm9/source/filesys/fsutil.c b/arm9/source/filesys/fsutil.c index ecf2390..39c9853 100644 --- a/arm9/source/filesys/fsutil.c +++ b/arm9/source/filesys/fsutil.c @@ -606,8 +606,8 @@ bool PathMoveCopy(const char* dest, const char* orig, u32* flags, bool move) { int odrvtype = DriveType(orig); char ldest[256]; // 256 is the maximum length of a full path char lorig[256]; - strncpy(ldest, dest, 255); - strncpy(lorig, orig, 255); + strncpy(ldest, dest, 256); + strncpy(lorig, orig, 256); char deststr[36 + 1]; TruncateString(deststr, ldest, 36, 8); @@ -883,6 +883,7 @@ bool FileSelector(char* result, const char* text, const char* path, const char* void* buffer = (void*) malloc(sizeof(DirStruct)); if (!buffer) return false; + // for this to work, result needs to be at least 256 bytes in size bool ret = FileSelectorWorker(result, text, path, pattern, flags, buffer, new_style); free(buffer); return ret; diff --git a/arm9/source/filesys/image.c b/arm9/source/filesys/image.c index 5289d0c..278ff9f 100644 --- a/arm9/source/filesys/image.c +++ b/arm9/source/filesys/image.c @@ -74,6 +74,6 @@ u64 MountImage(const char* path) { return 0; fvx_lseek(&mount_file, 0); fvx_sync(&mount_file); - strncpy(mount_path, path, 255); + strncpy(mount_path, path, 256); return (mount_state = type); } diff --git a/arm9/source/filesys/sddata.c b/arm9/source/filesys/sddata.c index 65ff846..1148cf2 100644 --- a/arm9/source/filesys/sddata.c +++ b/arm9/source/filesys/sddata.c @@ -35,9 +35,9 @@ int alias_num (const TCHAR* path) { void dealias_path (TCHAR* alias, const TCHAR* path) { int num = alias_num(path); u32 p_offs = (path[2] == '/' && ((path[3] == '/') || (path[3] == '\0'))) ? 3 : 2; - if (num >= 0) // set alias (alias is assumed to be 256 byte) + if (num >= 0) // set alias (alias is assumed to be 256 byte!) snprintf(alias, 256, "%s%s", alias_path[num], path + p_offs); - else strncpy(alias, path, 256); + else snprintf(alias, 256, "%s", path); } FilCryptInfo* fx_find_cryptinfo(FIL* fptr) { diff --git a/arm9/source/filesys/support.c b/arm9/source/filesys/support.c index cbfc1dc..0f261d4 100644 --- a/arm9/source/filesys/support.c +++ b/arm9/source/filesys/support.c @@ -115,6 +115,7 @@ bool CheckSupportDir(const char* dname) bool FileSelectorSupport(char* result, const char* text, const char* dname, const char* pattern) { char path[256]; + // result needs to be at least 256 bytes long for this to work! if (!GetSupportDir(path, dname)) return false; return FileSelector(result, text, path, pattern, HIDE_EXT, false); } diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index d4894a4..eb3966c 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -2194,7 +2194,7 @@ u32 GodMode(int entrypoint) { const u32 quick_stp = (MAIN_SCREEN == TOP_SCREEN) ? 20 : 19; u32 exit_mode = GODMODE_EXIT_POWEROFF; - char current_path[256] = { 0x00 }; + char current_path[256] = { 0x00 }; // don't change this size! u32 cursor = 0; u32 scroll = 0; diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index 30b9539..7e63440 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -238,12 +238,14 @@ u32 LoadCdnTicketFile(Ticket** ticket, const char* path_cnt) { } u32 GetTmdContentPath(char* path_content, const char* path_tmd) { + // path_content should be 256 bytes in size! + // get path to TMD first content static const u8 dlc_tid_high[] = { DLC_TID_HIGH }; // content path string char* name_content; - strncpy(path_content, path_tmd, 256); + snprintf(path_content, 255, "%s", path_tmd); path_content[255] = '\0'; name_content = strrchr(path_content, '/'); if (!name_content) return 1; // will not happen @@ -2450,6 +2452,8 @@ u32 ExtractCodeFromCxiFile(const char* path, const char* path_out, char* extstr) dest[255] = '\0'; if (!CheckWritePermissions(dest)) return 1; + // extstr should be at least 16 bytes in size + // NCSD handling u32 ncch_offset = 0; if (filetype & GAME_NCSD) { diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index d94aaab..fe2cd47 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -774,7 +774,7 @@ bool for_handler(char* path, const char* dir, const char* pattern, bool recursiv snprintf(path, 256, "%s/%.254s", ldir, fno.fname); if (rec && (fno.fattrib & AM_DIR) && (dp - fdir < _MAX_FOR_DEPTH - 1)) { if (fvx_opendir(++dp, path) != FR_OK) dp--; - else strncpy(ldir, path, 255); + else strncpy(ldir, path, 256); } } else return false; diff --git a/arm9/source/utils/sysinfo.c b/arm9/source/utils/sysinfo.c index 8f34ecd..c290b0a 100644 --- a/arm9/source/utils/sysinfo.c +++ b/arm9/source/utils/sysinfo.c @@ -244,6 +244,7 @@ void GetSysInfo_SecureInfo(SysInfo* info, char nand_drive) { // Determine the sub-model from the first two digits of the digit part. if (first_digit && second_digit) { if (IS_DEVKIT) { + // missing: identification for IS-CLOSER-BOX (issue #276) if ((first_digit == '9') && (second_digit == '0') && (info->int_model == MODEL_OLD_3DS)) { strncpy(info->sub_model, "Partner-CTR", countof("Partner-CTR")); } else if ((first_digit == '9') && (second_digit == '1') && (info->int_model == MODEL_OLD_3DS)) {