Skip to content

Commit cd100a2

Browse files
committed
CDVDFSV: Fixed pointer incorrectly getting incremented, when alignment correction is performed.
This resulted in the buffer getting overrun, causing memory corruption.
1 parent 71993a8 commit cd100a2

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

modules/iopcore/cdvdfsv/cdvdfsv.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ static inline void cdvd_readee(void *buf)
784784
u8 curlsn_buf[16];
785785
u32 nbytes, nsectors, sectors_to_read, size_64b, size_64bb, bytesent, temp;
786786
int sector_size, flag_64b, fsverror;
787-
void *fsvRbuf = (void *)cdvdfsv_buf;
788787
void *eeaddr_64b, *eeaddr2_64b;
789788
cdvdfsv_readee_t readee;
790789
RpcCdvd_t *r = (RpcCdvd_t *)buf;
@@ -828,7 +827,6 @@ static inline void cdvd_readee(void *buf)
828827
temp -= (u32)eeaddr2_64b;
829828
readee.pdst2 = eeaddr2_64b; // get the end address on a 64 bytes align
830829
readee.b2len = temp; // get bytes remainder at end of 64 bytes align
831-
fsvRbuf += temp;
832830

833831
if (readee.b1len)
834832
flag_64b = 0; // 64 bytes alignment flag
@@ -866,7 +864,7 @@ static inline void cdvd_readee(void *buf)
866864
temp = nsectors;
867865
}
868866

869-
if (sceCdRead(r->lsn, temp, (void *)fsvRbuf, NULL) == 0) {
867+
if (sceCdRead(r->lsn, temp, (void *)cdvdfsv_buf, NULL) == 0) {
870868
if (sceCdGetError() == CDVD_ERR_NO) {
871869
fsverror = CDVD_ERR_READCF;
872870
sceCdSC(CDSC_SET_ERROR, &fsverror);
@@ -882,14 +880,14 @@ static inline void cdvd_readee(void *buf)
882880

883881
if (!flag_64b) {
884882
if (sectors_to_read == r->sectors) // check that was the first read. Data read will be skewed by readee.b1len bytes into the adjacent sector.
885-
mips_memcpy((void *)readee.buf1, (void *)fsvRbuf, readee.b1len);
883+
mips_memcpy((void *)readee.buf1, (void *)cdvdfsv_buf, readee.b1len);
886884

887885
if ((sectors_to_read == nsectors) && (readee.b1len)) // For the last sector read.
888886
size_64bb = size_64b - 64;
889887
}
890888

891889
if (size_64bb > 0) {
892-
sysmemSendEE((void *)(fsvRbuf + readee.b1len), (void *)eeaddr_64b, size_64bb);
890+
sysmemSendEE((void *)(cdvdfsv_buf + readee.b1len), (void *)eeaddr_64b, size_64bb);
893891
bytesent += size_64bb;
894892
}
895893

@@ -903,7 +901,7 @@ static inline void cdvd_readee(void *buf)
903901
} while ((flag_64b) || (sectors_to_read));
904902

905903
//At the very last pass, copy readee.b2len bytes from the last sector, to complete the alignment correction.
906-
mips_memcpy((void *)readee.buf2, (void *)(fsvRbuf + size_64b - readee.b2len), readee.b2len);
904+
mips_memcpy((void *)readee.buf2, (void *)(cdvdfsv_buf + size_64b - readee.b2len), readee.b2len);
907905
}
908906

909907
*(int *)buf = bytesent;

modules/iopcore/cdvdman/cdvdman.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ static iop_sys_clock_t gCallbackSysClock;
210210
// buffers
211211
#define CDVDMAN_BUF_SECTORS 2
212212
static u8 cdvdman_buf[CDVDMAN_BUF_SECTORS * 2048];
213-
214-
#define CDVDMAN_FS_BUFSIZE CDVDMAN_FS_SECTORS * 2048
215-
static u8 cdvdman_fs_buf[CDVDMAN_FS_BUFSIZE];
213+
static u8 cdvdman_fs_buf[CDVDMAN_FS_SECTORS * 2048];
216214

217215
#define CDVDMAN_MODULE_VERSION 0x225
218216
static int cdvdman_debug_print_flag = 0;

0 commit comments

Comments
 (0)