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) {
|
||||
/* Open directory for listing. */
|
||||
DIR *dirp = opendir(dir->path);
|
||||
if (!dirp)
|
||||
goto next_dir;
|
||||
|
||||
/* Iterate through this directory's children to determine the entry array size. */
|
||||
size_t children_count = 3; /* include terminator, . and .. */
|
||||
if (dirp) { /* create empty directory if opendir failed */
|
||||
while ((readdir_entry = readdir(dirp))) {
|
||||
/* Ignore . and .. pseudo-directories. */
|
||||
if ((readdir_entry->d_name[0] == '.') && ((readdir_entry->d_name[1] == '\0') || (*((uint16_t *) &readdir_entry->d_name[1]) == '.')))
|
||||
continue;
|
||||
children_count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Grow array if needed. */
|
||||
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. */
|
||||
if (dirp) {
|
||||
rewinddir(dirp);
|
||||
while ((readdir_entry = readdir(dirp))) {
|
||||
/* Ignore . and .. pseudo-directories. */
|
||||
@@ -895,7 +896,7 @@ viso_init(const char *dirname, int *error)
|
||||
if (dir == eltorito_dir) {
|
||||
if (!stricmp(readdir_entry->d_name, "Boot-NoEmul.img")) {
|
||||
eltorito_type = 0x00;
|
||||
have_eltorito_entry:
|
||||
have_eltorito_entry:
|
||||
if (eltorito_entry)
|
||||
eltorito_others_present = 1; /* flag that the boot code directory contains other files */
|
||||
eltorito_entry = entry;
|
||||
@@ -930,6 +931,9 @@ have_eltorito_entry:
|
||||
|
||||
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. */
|
||||
dir_entries[children_count] = NULL;
|
||||
|
Reference in New Issue
Block a user