From 4024639e5de8cf7d3599854e94457c86e95a40fd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 15 Sep 2026 08:03:54 +0200 Subject: [PATCH] add NULL checks --- armsrc/iclass.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 0c4660838..826ce9ce1 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -455,6 +455,13 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) { // receive command uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE); + if (resp_anticoll == NULL || resp_csn == NULL || resp_conf == NULL || resp_cc == NULL || + resp_ff == NULL || resp_aia == NULL || receivedCmd == NULL) { + if (g_dbglevel >= DBG_ERROR) DbpString("iClass sim: failed to allocate buffers"); + BigBuf_free_keep_EM(); + return true; + } + // Prepare card messages tosend_t *ts = get_tosend(); @@ -501,6 +508,12 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf) { //Each bit is doubled when modulated for FPGA, and we also have SOF and EOF (2 bytes) uint8_t *data_response = BigBuf_calloc((34 * 2) + 3); + if (data_generic_trace == NULL || data_response == NULL) { + if (g_dbglevel >= DBG_ERROR) DbpString("iClass sim: failed to allocate buffers"); + BigBuf_free_keep_EM(); + return true; + } + enum { IDLE, ACTIVATED, SELECTED, HALTED } chip_state = IDLE; bool button_pressed = false; @@ -1098,6 +1111,13 @@ int do_iclass_simulation_nonsec(void) { // receive command uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE); + if (resp_anticoll == NULL || resp_csn == NULL || resp_conf == NULL || + resp_aia == NULL || receivedCmd == NULL) { + if (g_dbglevel >= DBG_ERROR) DbpString("iClass sim nonsec: failed to allocate buffers"); + BigBuf_free_keep_EM(); + return true; + } + // Prepare card messages tosend_t *ts = get_tosend(); ts->max = 0; @@ -1135,6 +1155,12 @@ int do_iclass_simulation_nonsec(void) { //Each bit is doubled when modulated for FPGA, and we also have SOF and EOF (2 bytes) uint8_t *data_response = BigBuf_calloc((32 + 2) * 2 + 2); + if (data_generic_trace == NULL || data_response == NULL) { + if (g_dbglevel >= DBG_ERROR) DbpString("iClass sim nonsec: failed to allocate buffers"); + BigBuf_free_keep_EM(); + return true; + } + enum { IDLE, ACTIVATED, SELECTED, HALTED } chip_state = IDLE; bool button_pressed = false;