struct {
struct file_info *first;
struct file_info **last;
+ int count;
} cache_files;
uint64_t current_position;
iso9660->magic = ISO9660_MAGIC;
iso9660->cache_files.first = NULL;
iso9660->cache_files.last = &(iso9660->cache_files.first);
+ iso9660->cache_files.count = 0;
/* Enable to support Joliet extensions by default. */
iso9660->opt_support_joliet = 1;
/* Enable to support Rock Ridge extensions by default. */
file = cache_get_entry(iso9660);
if (file != NULL) {
+ int cnt = 0;
while (file->parent != NULL && !file->parent->exposed) {
/* If file's parent is not exposed, it's moved
* to next entry of its parent. */
cache_add_to_next_of_parent(iso9660, file);
file = cache_get_entry(iso9660);
+ /* Prevent infnity loop caused by a broken ISO image. */
+ if (++cnt > iso9660->cache_files.count)
+ return (NULL);
}
return (file);
}
number = file->number;
iso9660->cache_files.first = NULL;
iso9660->cache_files.last = &(iso9660->cache_files.first);
+ iso9660->cache_files.count = 0;
empty_files.first = NULL;
empty_files.last = &empty_files.first;
/* Collect files which has the same file serial number.
file->next = NULL;
*iso9660->cache_files.last = file;
iso9660->cache_files.last = &(file->next);
+ iso9660->cache_files.count++;
}
static inline void
file->parent->next = file;
if (iso9660->cache_files.last == &(file->parent->next))
iso9660->cache_files.last = &(file->next);
+ iso9660->cache_files.count++;
}
static inline struct file_info *
iso9660->cache_files.first = file->next;
if (iso9660->cache_files.first == NULL)
iso9660->cache_files.last = &(iso9660->cache_files.first);
+ iso9660->cache_files.count--;
}
return (file);
}