From aabbf7d4b2874599710d21abee1bc4dd550685ad Mon Sep 17 00:00:00 2001 From: Yann GASCUEL <34003959+lnv42@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:47:59 +0100 Subject: [PATCH] iso15sim: enhance parameter controls and add reply when error --- armsrc/iso15693.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 83ad93ed0..03af8bcb9 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -2133,8 +2133,6 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { BigBuf_free_keep_EM(); iso15_tag_t *tag = (iso15_tag_t*) BigBuf_get_EM_addr(); - if (tag == NULL) return; - if (uid != NULL) { // new tag (need initialization) memcpy(tag->uid, uid, 8); tag->dsfid = 0; @@ -2146,14 +2144,21 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) { tag->ic = 0; memset(tag->locks, 0, sizeof(tag->locks)); memset(tag->data, 0, sizeof(tag->data)); + if (tag == NULL) + { + Dbprintf("Can't allocate emulator memory"); + reply_ng(CMD_HF_ISO15693_SIMULATE, PM3_EFAILED, NULL, 0); + return; } - else { // tag is already set - if (tag->pagesCount > ISO15693_TAG_MAX_PAGES || \ - tag->pagesCount * tag->bytesPerPage > ISO15693_TAG_MAX_SIZE) { - Dbprintf("Tag size error: pagesCount = %d, bytesPerPage=%d", tag->pagesCount, tag->bytesPerPage); - return; } } + if (tag->pagesCount > ISO15693_TAG_MAX_PAGES || \ + tag->pagesCount * tag->bytesPerPage > ISO15693_TAG_MAX_SIZE || + tag->pagesCount == 0 || tag->bytesPerPage == 0) { + Dbprintf("Tag size error: pagesCount = %d, bytesPerPage=%d", tag->pagesCount, tag->bytesPerPage); + reply_ng(CMD_HF_ISO15693_SIMULATE, PM3_EOPABORTED, NULL, 0); + return; + } Iso15693InitTag(); // init simulator