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/common.c | |
| parent | f7d9c309661f3027d5bfd119b3daf814e26ef589 (diff) | |
| download | psn00bsdk-870f4dca9d7b5e86544216d0e36863d17aefef62.tar.gz | |
Add argument validation to most libpsn00b functions
Diffstat (limited to 'libpsn00b/psxcd/common.c')
| -rw-r--r-- | libpsn00b/psxcd/common.c | 10 |
1 files changed, 8 insertions, 2 deletions
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); |
