Skip to content

Commit

Permalink
iso: fix nhddl crashing when directory name contains non-ASCII charac…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
pcm720 committed Oct 14, 2024
1 parent 0ccc660 commit 87e5577
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ TargetList *findISO() {
int _findISO(DIR *directory, TargetList *result) {
if (directory == NULL)
return -ENOENT;

// Read directory entries
struct dirent *entry;
char *fileext;
Expand All @@ -70,18 +71,22 @@ int _findISO(DIR *directory, TargetList *result) {
logString("ERROR: Failed to get cwd\n");
return -ENOENT;
}

int cwdLen = strlen(titlePath); // Get the length of base path string
while ((entry = readdir(directory)) != NULL) {
// Check if the entry is a directory using d_type
switch (entry->d_type) {
case DT_DIR:
if ((entry->d_name[0] == '.') || (entry->d_name[0] == '$')) // Ignore hidden and special folders
// Ignore hidden, special and invalid directories (non-ASCII paths seem to return '?' and cause crashes when used with opendir)
if ((entry->d_name[0] == '.') || (entry->d_name[0] == '$') || (entry->d_name[0] == '?'))
continue;

for (int i = 0; i < sizeof(ignoredDirs) / sizeof(char *); i++) {
if (!strcmp(ignoredDirs[i], entry->d_name)) {
goto skipDirectory;
}
}

// Open dir and change cwd
DIR *d = opendir(entry->d_name);
chdir(entry->d_name);
Expand Down

0 comments on commit 87e5577

Please sign in to comment.