1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-09 12:11:44 +00:00

nxdt_utils: use an arbitrary filename length limit for SD card paths

This commit is contained in:
Pablo Curiel 2023-07-17 23:44:45 +02:00
parent 3b4477262b
commit cd73c6360f
2 changed files with 10 additions and 6 deletions

View file

@ -160,6 +160,7 @@ bool utilsDeleteDirectoryRecursively(const char *path);
/// A path separator is automatically placed between the provided prefix and the filename if the prefix doesn't end with one.
/// A dot *isn't* automatically placed between the filename and the provided extension -- if required, it must be provided as part of the extension string.
/// Furthermore, if the full length for the generated path is >= FS_MAX_PATH, NULL will be returned.
/// The allocated buffer must be freed by the calling function using free().
char *utilsGeneratePath(const char *prefix, const char *filename, const char *extension);
/// Prints an error message using the standard console output and waits for the user to press a button.

View file

@ -33,7 +33,8 @@
#include "fatfs/ff.h"
/* Reference: https://docs.microsoft.com/en-us/windows/win32/fileio/filesystem-functionality-comparison#limits. */
#define NT_MAX_FILENAME_LENGTH 255
#define NT_MAX_FILENAME_LENGTH 255
#define SDMC_MAX_FILENAME_LENGTH 128 /* Arbitrarily set, I'm tired of FS sysmodule shenanigans. */
/* Type definitions. */
@ -872,6 +873,8 @@ char *utilsGeneratePath(const char *prefix, const char *filename, const char *ex
size_t path_len = (prefix_len + strlen(filename) + extension_len);
if (append_path_sep) path_len++;
size_t max_filename_len = ((use_prefix && !strncmp(prefix, DEVOPTAB_SDMC_DEVICE, strlen(DEVOPTAB_SDMC_DEVICE))) ? SDMC_MAX_FILENAME_LENGTH : NT_MAX_FILENAME_LENGTH);
char *path = NULL, *ptr1 = NULL, *ptr2 = NULL;
bool filename_only = false, success = false;
@ -896,7 +899,7 @@ char *utilsGeneratePath(const char *prefix, const char *filename, const char *ex
ptr1 = path;
}
/* Make sure each path element doesn't exceed NT_MAX_FILENAME_LENGTH. */
/* Make sure each path element doesn't exceed our max filename length. */
while(ptr1)
{
if (!filename_only)
@ -912,10 +915,10 @@ char *utilsGeneratePath(const char *prefix, const char *filename, const char *ex
size_t element_size = (ptr2 ? (size_t)(ptr2 - ptr1) : (path_len - (size_t)(ptr1 - path)));
/* Get UTF-8 codepoint count. */
/* Use NT_MAX_FILENAME_LENGTH as the codepoint count limit. */
/* Use our max filename length as the codepoint count limit. */
size_t last_cp_pos = 0;
size_t cp_count = utilsGetUtf8CodepointCount(ptr1, element_size, NT_MAX_FILENAME_LENGTH, &last_cp_pos);
if (cp_count > NT_MAX_FILENAME_LENGTH)
size_t cp_count = utilsGetUtf8CodepointCount(ptr1, element_size, max_filename_len, &last_cp_pos);
if (cp_count > max_filename_len)
{
if (ptr2)
{
@ -1141,7 +1144,7 @@ static void _utilsGetLaunchPath(int program_argc, const char **program_argv)
for(int i = 0; i < program_argc; i++)
{
if (program_argv[i] && !strncmp(program_argv[i], DEVOPTAB_SDMC_DEVICE "/", 6))
if (program_argv[i] && !strncmp(program_argv[i], DEVOPTAB_SDMC_DEVICE "/", strlen(DEVOPTAB_SDMC_DEVICE)))
{
g_appLaunchPath = program_argv[i];
break;