diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index a2fb98d17..58dd930fe 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -161,19 +161,21 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { g_conn.block_after_ACK = true; for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) { + // chunk size = what fits one frame to THIS device, minus the reply header + const int chunk = (int)(pm3_max_cmd_data_size() - sizeof(epa_replay_t)); // transfer the APDU in several parts if necessary - for (int j = 0; j * sizeof(data) < apdu_lengths[i]; j++) { + for (int j = 0; j * chunk < apdu_lengths[i]; j++) { // amount of data in this packet - int packet_length = apdu_lengths[i] - (j * sizeof(data)); - if (packet_length > sizeof(data)) { - packet_length = sizeof(data); + int packet_length = apdu_lengths[i] - (j * chunk); + if (packet_length > chunk) { + packet_length = chunk; } - if ((i == ARRAYLEN(apdu_lengths) - 1) && (j * sizeof(data) >= apdu_lengths[i] - 1)) { + if ((i == ARRAYLEN(apdu_lengths) - 1) && (j * chunk >= apdu_lengths[i] - 1)) { // Disable fast mode on last packet g_conn.block_after_ACK = false; } - memcpy(data, // + (j * sizeof(data)), - apdus[i] + (j * sizeof(data)), + memcpy(data, // + (j * chunk), + apdus[i] + (j * chunk), packet_length); clearCommandBuffer(); @@ -182,7 +184,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { uint8_t ubuf[sizeof(epa_replay_t) + sizeof(data)] = {0}; epa_replay_t *upayload = (epa_replay_t *)ubuf; upayload->apdu_num = i + 1; - upayload->offset = j * sizeof(data); + upayload->offset = j * chunk; upayload->len = packet_length; memcpy(upayload->data, data, packet_length); diff --git a/client/src/cmdhfvas.c b/client/src/cmdhfvas.c index f826f62ad..385ba18e1 100644 --- a/client/src/cmdhfvas.c +++ b/client/src/cmdhfvas.c @@ -702,7 +702,7 @@ static int VASGetData(const char *passIdentifier, const uint8_t *pidHash, bool h PrintAndLogEx(INFO, "Pass type id hash...... " _YELLOW_("%s"), hasPid ? sprint_hex_inrow(pidHash, 32) : "n/a"); } - uint8_t getVasApdu[PM3_CMD_DATA_SIZE]; + uint8_t getVasApdu[512]; // GET VAS DATA APDU: 6 + reqTlvLen, urlLen capped at 256 => <= 319 bytes int getVasApduLen = 0; int s = CreateGetVASDataCommand(pidHash, url, urlLen, vas_mode, isFinalRequest, getVasApdu, &getVasApduLen); if (s != PM3_SUCCESS) { diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 83d5cd3bc..4c6adfbef 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -360,7 +360,7 @@ int CmdLFCommandRead(const char *Cmd) { memset(payload.period_extra, 0, sizeof(payload.period_extra)); if (cmd_len > (size_t)(pm3_max_cmd_data_size() - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1) { - PrintAndLogEx(ERR, "cmd too long, max length is %zu", sizeof(cmd) - 1); + PrintAndLogEx(ERR, "cmd too long, max length is %zu", (size_t)(pm3_max_cmd_data_size() - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1); return PM3_EINVARG; } diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index a0faf1533..692abf406 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -1336,7 +1336,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) { int hexlen = 0; uint8_t cmddata[PM3_CMD_DATA_SIZE]; - int res = param_gethex_to_eol(caid, 0, cmddata, sizeof(cmddata), &hexlen); + int res = param_gethex_to_eol(caid, 0, cmddata, (int)(pm3_max_cmd_data_size() - sizeof(smart_card_raw_t)), &hexlen); if (res) { continue; } diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index f78091f18..370c57ce4 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -1139,7 +1139,7 @@ static int download_trace(void) { gs_traceLen = 0; - gs_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); + gs_trace = calloc(pm3_max_cmd_data_size(), sizeof(uint8_t)); if (gs_trace == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; @@ -1149,7 +1149,7 @@ static int download_trace(void) { // Query for the size of the trace, downloading PM3_CMD_DATA_SIZE PacketResponseNG resp; - if (!GetFromDevice(BIG_BUF, gs_trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &resp, 4000, true)) { + if (!GetFromDevice(BIG_BUF, gs_trace, pm3_max_cmd_data_size(), 0, NULL, 0, &resp, 4000, true)) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); free(gs_trace); gs_trace = NULL; @@ -1166,7 +1166,7 @@ static int download_trace(void) { gs_traceLen = ((const download_done_t *)resp.data.asBytes)->extra; // if tracelog buffer was larger and we need to download more. - if (gs_traceLen > PM3_CMD_DATA_SIZE) { + if (gs_traceLen > pm3_max_cmd_data_size()) { free(gs_trace); gs_trace = calloc(gs_traceLen, sizeof(uint8_t)); diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 44c02fb57..8dcae1ce7 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -637,7 +637,7 @@ static int CmdUsartTXhex(const char *Cmd) { int dlen = 0; uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; - int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, sizeof(data), &dlen); + int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, (int)pm3_max_cmd_data_size(), &dlen); CLIParserFree(ctx); if (res) {