fix coverity findings

This commit is contained in:
iceman1001 committed 2026-07-03 18:08:02 +02:00
1 parent 87388b3897
commit b8911a29a1
2 files changed
+42 -24

No files matched your search

+26 -15
View File
@@ -172,10 +172,11 @@ static int jooki_decode(uint8_t *b64, uint8_t *result) {
PrintAndLogEx(DEBUG, "(decode_jooki) raw encoded... " _GREEN_("%s"), sprint_hex(ndef, sizeof(ndef)));
for (uint8_t i = 0; i < JOOKI_PLAIN_LEN; i++) {
if (i < 3)
if (i < 3) {
result[i] = ndef[i] ^ nfc_secret[i];
else
} else {
result[i] = ndef[i] ^ nfc_secret[i] ^ ndef[i % 3] ^ nfc_secret[i % 3];
}
}
PrintAndLogEx(DEBUG, "(decode_jooki) plain......... %s", sprint_hex(result, sizeof(ndef)));
return PM3_SUCCESS;
@@ -239,9 +240,12 @@ static void jooki_print(uint8_t *b64, uint8_t *result, bool verbose) {
static int jooki_selftest(void) {
PrintAndLogEx(INFO, "======== " _CYAN_("self test") " ===========================================");
for (int i = 0; i < ARRAYLEN(jooks); i++) {
if (strlen(jooks[i].b64) == 0)
if (strlen(jooks[i].b64) == 0) {
continue;
}
uint8_t iv[JOOKI_IV_LEN] = {0};
uint8_t uid[JOOKI_UID_LEN] = {0};
@@ -409,11 +413,14 @@ static int CmdHF14AJookiEncode(const char *Cmd) {
fid = 0x0d;
uint8_t iv[JOOKI_IV_LEN] = {0x80, 0x77, 0x51};
if (use_tag) {
res = ul_read_uid(uid);
if (res != PM3_SUCCESS) {
return res;
}
} else {
if (ulen != JOOKI_UID_LEN) {
PrintAndLogEx(ERR, "Wrong length of UID, expect %u, got %d", JOOKI_UID_LEN, ulen);
@@ -442,14 +449,16 @@ static int CmdHF14AJookiDecode(const char *Cmd) {
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t b64[JOOKI_B64_LEN] = {0x00};
int dlen = sizeof(b64) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
memset(b64, 0x0, sizeof(b64));
CLIGetStrWithReturn(ctx, 1, b64, &dlen);
bool verbose = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
uint8_t result[JOOKI_PLAIN_LEN] = {0};
int res = jooki_decode(b64, result);
if (res == PM3_SUCCESS) {
jooki_print(b64, result, verbose);
@@ -471,9 +480,9 @@ static int CmdHF14AJookiSim(const char *Cmd) {
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint8_t b64[JOOKI_B64_LEN] = {0x00};
int dlen = sizeof(b64) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
memset(b64, 0x0, sizeof(b64));
CLIGetStrWithReturn(ctx, 1, b64, &dlen);
CLIParserFree(ctx);
@@ -533,7 +542,7 @@ static int CmdHF14AJookiSim(const char *Cmd) {
// fast push mode
g_conn.block_after_ACK = true;
uint8_t blockwidth = 4
uint8_t blockwidth = 4;
uint8_t counter = 0;
uint8_t blockno = 0;
@@ -595,11 +604,13 @@ static int CmdHF14AJookiSim(const char *Cmd) {
break;
}
if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == false)
if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == false) {
continue;
}
if (resp.status != PM3_SUCCESS)
if (resp.status != PM3_SUCCESS) {
break;
}
}
free(data);
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf 14a list") "` to view trace log");
@@ -623,26 +634,26 @@ static int CmdHF14AJookiClone(const char *Cmd) {
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t b64[JOOKI_B64_LEN] = {0x00};
int blen = sizeof(b64) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
memset(b64, 0x0, sizeof(b64));
CLIGetStrWithReturn(ctx, 1, b64, &blen);
int dlen = 0;
uint8_t data[52] = {0x00};
memset(data, 0x0, sizeof(data));
int res = CLIParamHexToBuf(arg_get_str(ctx, 2), data, sizeof(data), &dlen);
if (res) {
CLIParserFree(ctx);
PrintAndLogEx(FAILED, "Error parsing bytes");
return PM3_EINVARG;
}
int plen = 0;
uint8_t pwd[4] = {0x00};
CLIGetHexWithReturn(ctx, 3, pwd, &plen);
CLIParserFree(ctx);
// sanity checks
if (res) {
PrintAndLogEx(FAILED, "Error parsing bytes");
return PM3_EINVARG;
}
if (dlen != 52) {
PrintAndLogEx(ERR, "Wrong data length. Expected 52 got %d", dlen);
return PM3_EINVARG;