From: Toni Wilen Date: Sat, 21 Sep 2019 10:42:20 +0000 (+0300) Subject: Validate returned track, it may not exist in some situations. X-Git-Tag: 4300~106 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=0a107913323d170d470e647d4cb6034f131cb1df;p=francis%2Fwinuae.git Validate returned track, it may not exist in some situations. --- diff --git a/blkdev.cpp b/blkdev.cpp index 7005e05d..3ea03436 100644 --- a/blkdev.cpp +++ b/blkdev.cpp @@ -114,6 +114,8 @@ static struct cd_toc *gettoc (int unitnum, struct cd_toc_head *th, int block) int cdtracknumber(struct cd_toc_head *th, int block) { struct cd_toc *t = gettoc(-1, th, block); + if (!t) + return -1; return t->track; } int isaudiotrack (struct cd_toc_head *th, int block) diff --git a/od-win32/blkdev_win32_ioctl.cpp b/od-win32/blkdev_win32_ioctl.cpp index 90654e37..017b0c53 100644 --- a/od-win32/blkdev_win32_ioctl.cpp +++ b/od-win32/blkdev_win32_ioctl.cpp @@ -340,6 +340,8 @@ retry: ret = 0; while (size > 0) { int track = cdtracknumber(&ciw->di.toc, sector); + if (track < 0) + return 0; got = false; if (!ciw->usesptiread && sectorsize == 2048 && ciw->trackmode[track] == 0) { if (read2048 (ciw, sector) == 2048) { diff --git a/od-win32/blkdev_win32_spti.cpp b/od-win32/blkdev_win32_spti.cpp index 502fd94d..412e751b 100644 --- a/od-win32/blkdev_win32_spti.cpp +++ b/od-win32/blkdev_win32_spti.cpp @@ -168,9 +168,10 @@ static int execscsicmd (struct dev_info_spti *di, int unitnum, uae_u8 *data, int if (!bypass) { if (data[0] == 0x03 && di->senselen > 0) { - memcpy(inbuf, di->sense, di->senselen); + int l = di->senselen > inlen ? inlen : di->senselen; + memcpy(inbuf, di->sense, l); di->senselen = 0; - return di->senselen; + return l; } int r = blkdev_is_audio_command(data[0]); if (r > 0) { @@ -376,15 +377,16 @@ static uae_u8 *execscsicmd_in_internal (struct dev_info_spti *di, int unitnum, u static void close_scsi_device2 (struct dev_info_spti *di) { + di->cda.subcodevalid = false; if (di->open == false) return; + di->open = false; if (di->handle != INVALID_HANDLE_VALUE) { CloseHandle(di->handle); uae_sem_destroy(&di->cda.sub_sem); uae_sem_destroy(&di->cda.sub_sem2); } di->handle = INVALID_HANDLE_VALUE; - di->open = false; } static void close_scsi_device (int unitnum) @@ -1096,14 +1098,18 @@ static int ioctl_command_qcode(int unitnum, uae_u8 *buf, int sector, bool all) } else { int pos = di->cda.cd_last_pos; int trk = cdtracknumber(&di->di.toc, pos); - struct cd_toc *t = &di->di.toc.toc[trk]; - p[0] = (t->control << 4) | (t->adr << 0); - p[1] = tobcd(trk); - p[2] = tobcd(1); - uae_u32 msf = lsn2msf(pos); - tolongbcd(p + 7, msf); - msf = lsn2msf(pos - t->paddress - 150); - tolongbcd(p + 3, msf); + if (trk >= 0) { + struct cd_toc *t = &di->di.toc.toc[trk]; + p[0] = (t->control << 4) | (t->adr << 0); + p[1] = tobcd(trk); + p[2] = tobcd(1); + uae_u32 msf = lsn2msf(pos); + tolongbcd(p + 7, msf); + msf = lsn2msf(pos - t->paddress - 150); + tolongbcd(p + 3, msf); + } else { + p[1] = AUDIO_STATUS_NO_STATUS; + } } return 1;