From 6c3e3c7a449e51ca03d9a197ef8f6b1a9270ff0c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 2 Jul 2026 16:48:17 +0200 Subject: [PATCH] fix several coverity findings --- armsrc/hitagS.c | 7 +++---- armsrc/hitagu.c | 9 ++++++--- armsrc/i2c.c | 13 ------------- armsrc/i2c_direct.c | 18 +++--------------- armsrc/iclass.c | 18 ++++++++++++------ 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index c1bacd09a..b1afc9f49 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -702,22 +702,21 @@ void hts_read(const lf_hitag_data_t *payload, bool ledcontrol) { uint8_t rx[HITAG_FRAME_LEN] = { 0x00 }; uint8_t tx[HITAG_FRAME_LEN] = { 0x00 }; + lf_hts_read_response_t card = {0}; - int status = PM3_SUCCESS, reason = -1; - reason = hts_select_tag(payload, tx, ARRAYLEN(tx), rx, ARRAYLEN(rx), HITAG_T_WAIT_FIRST, ledcontrol); + int status = PM3_SUCCESS; + int reason = hts_select_tag(payload, tx, ARRAYLEN(tx), rx, ARRAYLEN(rx), HITAG_T_WAIT_FIRST, ledcontrol); if (reason != 0) { status = PM3_ERFTRANS; goto read_end; } - if (payload->page >= tag.max_page) { DBG Dbprintf("Warning, read page "_YELLOW_("%d") " > max page("_YELLOW_("%d") ") ", payload->page, tag.max_page); } int page_addr = payload->page; int page_index = 0; - lf_hts_read_response_t card = {0}; memcpy(card.config_page.asBytes, tag.data.pages[HITAGS_CONFIG_PADR], HITAGS_PAGE_SIZE); diff --git a/armsrc/hitagu.c b/armsrc/hitagu.c index 3f9377650..34e337803 100644 --- a/armsrc/hitagu.c +++ b/armsrc/hitagu.c @@ -693,10 +693,15 @@ exit: * Reads a Hitag ยต tag */ void htu_read(const lf_hitag_data_t *payload, bool ledcontrol) { + size_t rxlen = 0; uint8_t rx[HITAG_FRAME_LEN] = {0x00}; + size_t txlen = 0; uint8_t tx[HITAG_FRAME_LEN] = {0x00}; + + lf_htu_read_response_t card = {0}; + int status = PM3_SUCCESS; // DBG { @@ -719,9 +724,7 @@ void htu_read(const lf_hitag_data_t *payload, bool ledcontrol) { goto exit; } - lf_htu_read_response_t card = { - .icr = tag.icr, - }; + card.icr = tag.icr; memcpy(card.uid, tag.uid, HITAGU_UID_SIZE); memcpy(card.config_page.asBytes, tag.config.asBytes, HITAGU_BLOCK_SIZE); diff --git a/armsrc/i2c.c b/armsrc/i2c.c index d5994969d..4df227d18 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -494,8 +494,6 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t return 0; } -// uint8_t *pd = data; - // extra wait 500us (514us measured) // 200us (xx measured) WaitUS(600); @@ -592,13 +590,6 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t I2C_Stop(); -// Dbprintf("rec len... %u readcount... %u", recv_len, readcount); -// Dbhexdump(readcount, pd, false); - - if (readcount < 2) { - return 0; - } - // return bytecount - bytes encoding length return readcount - 2; } @@ -769,10 +760,6 @@ bool sc_rx_bytes(uint8_t *dest, uint16_t *destlen, uint32_t wait) { } } - if (len < 1) { - return false; - } - *destlen = len; return true; } diff --git a/armsrc/i2c_direct.c b/armsrc/i2c_direct.c index 6685cac59..dd3b49fd1 100644 --- a/armsrc/i2c_direct.c +++ b/armsrc/i2c_direct.c @@ -201,31 +201,19 @@ int CmdSmartRaw(const uint8_t prepend, const uint8_t *data, int dlen, uint8_t *o payload->len = dlen; memcpy(payload->data, data, dlen); - payload->flags = SC_LOG; - bool active = true; - bool active_select = false; int timeout = 600; - bool use_t0 = true; - - if (active || active_select) { - payload->flags |= (SC_CONNECT | SC_CLEARLOG); - if (active_select) - payload->flags |= SC_SELECT; - } + payload->flags = ( SC_LOG | SC_CONNECT | SC_CLEARLOG ); payload->wait_delay = 0; + if (timeout > -1) { payload->flags |= SC_WAIT; payload->wait_delay = timeout; } if (dlen > 0) { - if (use_t0) - payload->flags |= SC_RAW_T0; - else - payload->flags |= SC_RAW; + payload->flags |= SC_RAW_T0; } - SmartCardDirectSend(prepend, payload, output, olen, 0); return PM3_SUCCESS; diff --git a/armsrc/iclass.c b/armsrc/iclass.c index a5c9e338e..e98e1f77e 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1663,8 +1663,9 @@ void iClass_Authentication_fast(iclass_chk_t *p) { uint8_t resp[ICLASS_BUFFER_SIZE] = {0}; uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 }; - if (p->use_credit_key) + if (p->use_credit_key) { readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK; + } // select card / e-purse picopass_hdr_t hdr = {0}; @@ -1678,10 +1679,13 @@ void iClass_Authentication_fast(iclass_chk_t *p) { Iso15693InitReader(); bool isOK = false; + uint8_t i = 0; + uint32_t start_time = 0; + uint32_t eof_time = 0; - uint32_t start_time = 0, eof_time = 0; - if (select_iclass_tag(&hdr, p->use_credit_key, &eof_time, shallow_mod) == false) + if (select_iclass_tag(&hdr, p->use_credit_key, &eof_time, shallow_mod) == false) { goto out; + } start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER; @@ -1689,12 +1693,13 @@ void iClass_Authentication_fast(iclass_chk_t *p) { uint16_t checked = 0; // Keychunk loop - uint8_t i = 0; for (i = 0; i < p->count; i++) { // Allow button press / usb cmd to interrupt device if (checked == 1000) { - if (BUTTON_PRESS() || data_available()) goto out; + if (BUTTON_PRESS() || data_available()) { + goto out; + } checked = 0; } ++checked; @@ -1710,8 +1715,9 @@ void iClass_Authentication_fast(iclass_chk_t *p) { // expect 4bytes, 3 retries times.. isOK = iclass_send_cmd_with_retries(check, sizeof(check), resp, sizeof(resp), 4, 2, &start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time, shallow_mod); - if (isOK) + if (isOK) { goto out; + } start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER; // Auth Sequence MUST begin with reading e-purse. (block2)