diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-04-04 15:09:38 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-04-04 15:09:38 +0200 |
| commit | 870f4dca9d7b5e86544216d0e36863d17aefef62 (patch) | |
| tree | f6186004da976cea19ee5764b795a51f932f77fb /libpsn00b/psxcd | |
| parent | f7d9c309661f3027d5bfd119b3daf814e26ef589 (diff) | |
| download | psn00bsdk-870f4dca9d7b5e86544216d0e36863d17aefef62.tar.gz | |
Add argument validation to most libpsn00b functions
Diffstat (limited to 'libpsn00b/psxcd')
| -rw-r--r-- | libpsn00b/psxcd/cdread.c | 2 | ||||
| -rw-r--r-- | libpsn00b/psxcd/common.c | 10 | ||||
| -rw-r--r-- | libpsn00b/psxcd/isofs.c | 13 | ||||
| -rw-r--r-- | libpsn00b/psxcd/misc.c | 8 |
4 files changed, 31 insertions, 2 deletions
diff --git a/libpsn00b/psxcd/cdread.c b/libpsn00b/psxcd/cdread.c index d211a01..1adc255 100644 --- a/libpsn00b/psxcd/cdread.c +++ b/libpsn00b/psxcd/cdread.c @@ -89,6 +89,8 @@ static int _poll_retry(void) { /* Public API */ int CdReadRetry(int sectors, uint32_t *buf, int mode, int attempts) { + _sdk_validate_args((sectors > 0) && buf && (attempts > 0), -1); + if (CdReadSync(1, 0) > 0) { _sdk_log("CdRead() failed, another read in progress (%d sectors pending)\n", _pending_sectors); return 0; diff --git a/libpsn00b/psxcd/common.c b/libpsn00b/psxcd/common.c index c8f01d1..461ab91 100644 --- a/libpsn00b/psxcd/common.c +++ b/libpsn00b/psxcd/common.c @@ -244,6 +244,8 @@ int CdInit(void) { /* Low-level command API */ int CdCommandF(CdlCommand cmd, const void *param, int length) { + _sdk_validate_args(param || (length <= 0), -1); + const uint8_t *_param = (const uint8_t *) param; _last_command = (uint8_t) cmd; @@ -283,7 +285,7 @@ int CdCommandF(CdlCommand cmd, const void *param, int length) { __asm__ volatile(""); CD_REG(0) = 0; - for (; length; length--) + for (; length > 0; length--) CD_REG(2) = *(_param++); CD_REG(0) = 0; @@ -292,6 +294,8 @@ int CdCommandF(CdlCommand cmd, const void *param, int length) { } int CdCommand(CdlCommand cmd, const void *param, int length, uint8_t *result) { + _sdk_validate_args(param || (length <= 0), -1); + /*if (_ack_pending) { _sdk_log("CdCommand(0x%02x) failed, drive busy\n", cmd); return 0; @@ -329,8 +333,10 @@ int CdControlF(CdlCommand cmd, const void *param) { } else { // The command takes a mandatory parameter or no parameter. length = flags & 3; - if (length && !param) + if (length && !param) { + _sdk_log("CdControl() param is required for command 0x%02x\n", cmd); return -1; + } } return CdCommandF(cmd, param, length); diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 0ac782b..5fd0536 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -450,6 +450,8 @@ static char* get_filename(char *name, const char *filename) CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) { + _sdk_validate_args(fp && filename, NULL); + int i,j,found_dir,num_dirs; int dir_len; char tpath_rbuff[128]; @@ -553,6 +555,8 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) CdlDIR *CdOpenDir(const char* path) { + _sdk_validate_args(path, NULL); + CdlDIR_INT* dir; int num_dirs; int i,found_dir; @@ -631,6 +635,8 @@ CdlDIR *CdOpenDir(const char* path) int CdReadDir(CdlDIR *dir, CdlFILE* file) { + _sdk_validate_args(dir && file, 0); + CdlDIR_INT* d_dir; ISO_DIR_ENTRY* dir_entry; @@ -683,6 +689,9 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file) void CdCloseDir(CdlDIR *dir) { + if (!dir) + return; + CdlDIR_INT* d_dir; d_dir = (CdlDIR_INT*)dir; @@ -698,6 +707,8 @@ int CdIsoError() int CdGetVolumeLabel(char *label) { + _sdk_validate_args(label, -1); + int i, length = 31; ISO_DESCRIPTOR* descriptor; @@ -761,6 +772,8 @@ static void _scan_callback(CdlIntrResult status, unsigned char *result) int CdLoadSession(int session) { + _sdk_validate_args(session >= 0, -1); + CdlLOC *loc; CdlCB ready_oldcb; char scanbuff[2048]; diff --git a/libpsn00b/psxcd/misc.c b/libpsn00b/psxcd/misc.c index 851fea6..2f04821 100644 --- a/libpsn00b/psxcd/misc.c +++ b/libpsn00b/psxcd/misc.c @@ -33,6 +33,8 @@ static const char *const _unlock_regions[] = { /* Sector DMA transfer functions */ int CdGetSector(void *madr, int size) { + _sdk_validate_args(madr && (size > 0), 0); + //while (!(CD_REG(0) & (1 << 6))) //__asm__ volatile(""); @@ -47,6 +49,8 @@ int CdGetSector(void *madr, int size) { } int CdGetSector2(void *madr, int size) { + _sdk_validate_args(madr && (size > 0), 0); + //while (!(CD_REG(0) & (1 << 6))) //__asm__ volatile(""); @@ -170,6 +174,8 @@ int CdUnlock(CdlRegionCode region) { /* Misc. functions */ int CdGetToc(CdlLOC *toc) { + _sdk_validate_args(toc, 0); + uint8_t result[4]; if (!CdCommand(CdlGetTN, 0, 0, result)) @@ -199,6 +205,8 @@ int CdGetToc(CdlLOC *toc) { } int CdMix(const CdlATV *vol) { + _sdk_validate_args(vol, 0); + CD_REG(0) = 2; CD_REG(2) = vol->val0; CD_REG(3) = vol->val1; |
