cdrom: initialize all buffers used for drive paths, make sure to null-terminate filled paths in all cases

This commit is contained in:
Brad Parker 2019-08-12 20:42:40 -04:00
parent 6065f71bb2
commit 3432f3b852
4 changed files with 13 additions and 13 deletions

View File

@ -1494,9 +1494,7 @@ bool cdrom_is_media_inserted(libretro_vfs_implementation_file *stream)
bool cdrom_drive_has_media(const char drive)
{
RFILE *file;
char cdrom_path_bin[256];
cdrom_path_bin[0] = '\0';
char cdrom_path_bin[256] = {0};
cdrom_device_fillpath(cdrom_path_bin, sizeof(cdrom_path_bin), drive, 1, false);
@ -1690,8 +1688,11 @@ void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char tra
#ifdef __linux__
pos = strlcpy(path, "cdrom://drive", len);
if (len > pos)
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
}
pos = strlcat(path, ".cue", len);
#endif
@ -1702,8 +1703,11 @@ void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char tra
#ifdef _WIN32
pos = strlcpy(path, "cdrom://", len);
if (len > pos)
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
}
pos += snprintf(path + pos, len - pos, ":/drive-track%02d.bin", track);
#else

View File

@ -2263,9 +2263,7 @@ static int action_ok_load_cdrom(const char *path,
if (system && !string_is_empty(system->library_name))
{
char cdrom_path[256];
cdrom_path[0] = '\0';
char cdrom_path[256] = {0};
cdrom_device_fillpath(cdrom_path, sizeof(cdrom_path), label[0], 0, true);

View File

@ -5187,14 +5187,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
case DISPLAYLIST_CDROM_DETAIL_INFO:
{
media_detect_cd_info_t cd_info = {{0}};
char file_path[PATH_MAX_LENGTH];
char file_path[PATH_MAX_LENGTH] = {0};
RFILE *file;
char drive = info->path[0];
bool atip = false;
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
count = 0;
file_path[0] = '\0';
if (cdrom_drive_has_media(drive))
{
@ -5226,6 +5225,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
}
/* open first data track */
memset(file_path, 0, sizeof(file_path));
cdrom_device_fillpath(file_path, sizeof(file_path), drive, first_data_track, false);
if (media_detect_cd_info(file_path, 0, &cd_info))

View File

@ -230,9 +230,7 @@ static void task_cdrom_dump_handler(retro_task_t *task)
case DUMP_STATE_TOC_PENDING:
{
/* open cuesheet file from drive */
char cue_path[PATH_MAX_LENGTH];
cue_path[0] = '\0';
char cue_path[PATH_MAX_LENGTH] = {0};
cdrom_device_fillpath(cue_path, sizeof(cue_path), state->drive_letter[0], 0, true);