]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Validate returned track, it may not exist in some situations.
authorToni Wilen <twilen@winuae.net>
Sat, 21 Sep 2019 10:42:20 +0000 (13:42 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 21 Sep 2019 10:42:20 +0000 (13:42 +0300)
blkdev.cpp
od-win32/blkdev_win32_ioctl.cpp
od-win32/blkdev_win32_spti.cpp

index 7005e05de5d9d74573b8dbca2c2e3b1773c13caf..3ea03436e363d4e9e7dedf7e58e932886b61d3ea 100644 (file)
@@ -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)
index 90654e37cd1be061722bb7e426ab54b28df232d5..017b0c530cffa26e77df1516f5bcbb46af0a1717 100644 (file)
@@ -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) {
index 502fd94d8e949f80ffa1597085942d28dee98bd2..412e751b2e42f60e7924d03881a9b411876dec0f 100644 (file)
@@ -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;