VISO: Fix segfault if a directory fails to be enumerated
This commit is contained in:
@@ -812,17 +812,17 @@ viso_init(const char *dirname, int *error)
|
|||||||
while (dir) {
|
while (dir) {
|
||||||
/* Open directory for listing. */
|
/* Open directory for listing. */
|
||||||
DIR *dirp = opendir(dir->path);
|
DIR *dirp = opendir(dir->path);
|
||||||
if (!dirp)
|
|
||||||
goto next_dir;
|
|
||||||
|
|
||||||
/* Iterate through this directory's children to determine the entry array size. */
|
/* Iterate through this directory's children to determine the entry array size. */
|
||||||
size_t children_count = 3; /* include terminator, . and .. */
|
size_t children_count = 3; /* include terminator, . and .. */
|
||||||
|
if (dirp) { /* create empty directory if opendir failed */
|
||||||
while ((readdir_entry = readdir(dirp))) {
|
while ((readdir_entry = readdir(dirp))) {
|
||||||
/* Ignore . and .. pseudo-directories. */
|
/* Ignore . and .. pseudo-directories. */
|
||||||
if ((readdir_entry->d_name[0] == '.') && ((readdir_entry->d_name[1] == '\0') || (*((uint16_t *) &readdir_entry->d_name[1]) == '.')))
|
if ((readdir_entry->d_name[0] == '.') && ((readdir_entry->d_name[1] == '\0') || (*((uint16_t *) &readdir_entry->d_name[1]) == '.')))
|
||||||
continue;
|
continue;
|
||||||
children_count++;
|
children_count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Grow array if needed. */
|
/* Grow array if needed. */
|
||||||
if (children_count > dir_entries_len) {
|
if (children_count > dir_entries_len) {
|
||||||
@@ -858,6 +858,7 @@ viso_init(const char *dirname, int *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate through this directory's children again, making the entries. */
|
/* Iterate through this directory's children again, making the entries. */
|
||||||
|
if (dirp) {
|
||||||
rewinddir(dirp);
|
rewinddir(dirp);
|
||||||
while ((readdir_entry = readdir(dirp))) {
|
while ((readdir_entry = readdir(dirp))) {
|
||||||
/* Ignore . and .. pseudo-directories. */
|
/* Ignore . and .. pseudo-directories. */
|
||||||
@@ -930,6 +931,9 @@ have_eltorito_entry:
|
|||||||
|
|
||||||
cdrom_image_viso_log("[%08X] %s => [%-12s] %s\n", entry, dir->path, entry->name_short, entry->basename);
|
cdrom_image_viso_log("[%08X] %s => [%-12s] %s\n", entry, dir->path, entry->name_short, entry->basename);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cdrom_image_viso_log("VISO: Failed to enumerate [%s], will be empty\n", dir->path);
|
||||||
|
}
|
||||||
|
|
||||||
/* Add terminator. */
|
/* Add terminator. */
|
||||||
dir_entries[children_count] = NULL;
|
dir_entries[children_count] = NULL;
|
||||||
|
Reference in New Issue
Block a user