mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 21:33:19 -07:00
Code cleanup (#616)
* coverity fixes (including a real bug in cmdhftopaz.c) * Typo fix * replace TRUE/FALSE by stdbool true/false
This commit is contained in:
parent
2bb7f7e327
commit
44964fd181
30 changed files with 198 additions and 212 deletions
|
@ -361,7 +361,7 @@ int CmdHFList(const char *Cmd)
|
|||
char param2 = '\0';
|
||||
char param3 = '\0';
|
||||
char type[40] = {0};
|
||||
char filename[FILE_PATH_SIZE];
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
uint8_t protocol = 0;
|
||||
|
||||
// parse command line
|
||||
|
|
|
@ -486,12 +486,12 @@ int CmdHF14AInfo(const char *Cmd)
|
|||
|
||||
|
||||
// try to see if card responses to "chinese magic backdoor" commands.
|
||||
mfCIdentify();
|
||||
(void)mfCIdentify();
|
||||
|
||||
if (isMifareClassic) {
|
||||
switch(DetectClassicPrng()) {
|
||||
case 0:
|
||||
PrintAndLog("Prng detection: HARDEND (hardnested)");
|
||||
PrintAndLog("Prng detection: HARDENED (hardnested)");
|
||||
break;
|
||||
case 1:
|
||||
PrintAndLog("Prng detection: WEAK");
|
||||
|
@ -1032,12 +1032,9 @@ static command_t CommandTable[] =
|
|||
};
|
||||
|
||||
int CmdHF14A(const char *Cmd) {
|
||||
// flush
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
// parse
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
|
|
|
@ -202,10 +202,7 @@ int CmdHelp(const char *Cmd)
|
|||
|
||||
int CmdHFEPA(const char *Cmd)
|
||||
{
|
||||
// flush
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
// parse
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -559,8 +559,10 @@ bool NestedCheckKey(uint64_t key, TAuthData *ad, uint8_t *cmd, uint8_t cmdsize,
|
|||
uint32_t ar1 = crypto1_word(pcs, 0, 0) ^ ad->ar_enc;
|
||||
uint32_t at1 = crypto1_word(pcs, 0, 0) ^ ad->at_enc;
|
||||
|
||||
if (!(ar == ar1 && at == at1 && NTParityChk(ad, nt1)))
|
||||
if (!(ar == ar1 && at == at1 && NTParityChk(ad, nt1))) {
|
||||
crypto1_destroy(pcs);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(buf, cmd, cmdsize);
|
||||
mf_crypto1_decrypt(pcs, buf, cmdsize, 0);
|
||||
|
|
|
@ -726,7 +726,6 @@ int CmdHF14AMfNested(const char *Cmd)
|
|||
blockNo = i * 4;
|
||||
keyType = j;
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
|
||||
keyFound = true;
|
||||
break;
|
||||
}
|
||||
|
@ -737,6 +736,7 @@ int CmdHF14AMfNested(const char *Cmd)
|
|||
// Can't found a key....
|
||||
if (!keyFound) {
|
||||
PrintAndLog("Can't found any of the known keys.");
|
||||
free(e_sector);
|
||||
return 4;
|
||||
}
|
||||
PrintAndLog("--auto key. block no:%3d, key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));
|
||||
|
@ -1187,7 +1187,10 @@ int CmdHF14AMfChk(const char *Cmd)
|
|||
|
||||
// initialize storage for found keys
|
||||
e_sector = calloc(SectorsCnt, sizeof(sector_t));
|
||||
if (e_sector == NULL) return 1;
|
||||
if (e_sector == NULL) {
|
||||
free(keyBlock);
|
||||
return 1;
|
||||
}
|
||||
for (uint8_t keyAB = 0; keyAB < 2; keyAB++) {
|
||||
for (uint16_t sectorNo = 0; sectorNo < SectorsCnt; sectorNo++) {
|
||||
e_sector[sectorNo].Key[keyAB] = 0xffffffffffff;
|
||||
|
@ -2666,11 +2669,9 @@ static command_t CommandTable[] =
|
|||
|
||||
int CmdHFMF(const char *Cmd)
|
||||
{
|
||||
// flush
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
|
|
|
@ -276,7 +276,6 @@ static void init_bitflip_bitarrays(void)
|
|||
if (bytesread != filesize) {
|
||||
printf("File read error with %s. Aborting...\n", state_file_name);
|
||||
fclose(statesfile);
|
||||
inflateEnd(&compressed_stream);
|
||||
exit(5);
|
||||
}
|
||||
fclose(statesfile);
|
||||
|
|
|
@ -1834,7 +1834,7 @@ static command_t CommandTable[] =
|
|||
};
|
||||
|
||||
int CmdHFMFUltra(const char *Cmd){
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -455,7 +455,7 @@ int CmdHFTopazReader(const char *Cmd)
|
|||
PrintAndLog("HR0 : %02x (%sa Topaz tag (%scapable of carrying a NDEF message), %s memory map)", rid_response[0],
|
||||
(rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
|
||||
(rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
|
||||
(rid_response[0] & 0x0F) == 0x10 ? "static" : "dynamic");
|
||||
(rid_response[0] & 0x0F) == 0x01 ? "static" : "dynamic");
|
||||
PrintAndLog("HR1 : %02x", rid_response[1]);
|
||||
|
||||
status = topaz_rall(uid_echo, rall_response);
|
||||
|
@ -554,10 +554,7 @@ static command_t CommandTable[] =
|
|||
|
||||
|
||||
int CmdHFTopaz(const char *Cmd) {
|
||||
// flush
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
// parse
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ int CmdLFHitagList(const char *Cmd)
|
|||
if (strlen(filename) > 0) {
|
||||
if ((pf = fopen(filename,"wb")) == NULL) {
|
||||
PrintAndLog("Error: Could not open file [%s]",filename);
|
||||
free(got);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -166,11 +167,11 @@ int CmdLFHitagSim(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
tag_mem_supplied = true;
|
||||
if (fread(c.d.asBytes,48,1,pf) == 0) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
fclose(pf);
|
||||
if (fread(c.d.asBytes,1,48,pf) != 48) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
fclose(pf);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
fclose(pf);
|
||||
} else {
|
||||
tag_mem_supplied = false;
|
||||
|
@ -289,7 +290,7 @@ int CmdLFHitagSimS(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
tag_mem_supplied = true;
|
||||
if (fread(c.d.asBytes, 4*64, 1, pf) == 0) {
|
||||
if (fread(c.d.asBytes, 1, 4*64, pf) != 4*64) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
fclose(pf);
|
||||
return 1;
|
||||
|
@ -321,9 +322,9 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
file_given = true;
|
||||
if (fread(c.d.asBytes,8*60,1,pf) == 0) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
fclose(pf);
|
||||
if (fread(c.d.asBytes,1,8*60,pf) != 8*60) {
|
||||
PrintAndLog("Error: File reading error");
|
||||
fclose(pf);
|
||||
return 1;
|
||||
}
|
||||
fclose(pf);
|
||||
|
|
|
@ -287,7 +287,7 @@ int CmdIndalaDemod(const char *Cmd) {
|
|||
}
|
||||
|
||||
int CmdIndalaClone(const char *Cmd) {
|
||||
UsbCommand c;
|
||||
UsbCommand c = {0};
|
||||
unsigned int uid1, uid2, uid3, uid4, uid5, uid6, uid7;
|
||||
|
||||
uid1 = uid2 = uid3 = uid4 = uid5 = uid6 = uid7 = 0;
|
||||
|
|
|
@ -105,7 +105,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl)
|
|||
int res = rsa_check_pubkey(&cp->ctx);
|
||||
if(res != 0) {
|
||||
fprintf(stderr, "PolarSSL public key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
|
||||
|
||||
free(cp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl)
|
|||
int res = rsa_check_privkey(&cp->ctx);
|
||||
if(res != 0) {
|
||||
fprintf(stderr, "PolarSSL private key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
|
||||
free(cp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -184,6 +185,7 @@ static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl)
|
|||
int res = rsa_gen_key(&cp->ctx, &myrand, NULL, nbits, exp);
|
||||
if (res) {
|
||||
fprintf(stderr, "PolarSSL private key generation error res=%x exp=%d nbits=%d.\n", res * -1, exp, nbits);
|
||||
free(cp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -216,6 +218,7 @@ static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, co
|
|||
res = rsa_public(&cp->ctx, buf, result);
|
||||
if(res) {
|
||||
printf("RSA encrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -242,6 +245,7 @@ static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, co
|
|||
res = rsa_private(&cp->ctx, buf, result); // CHECK???
|
||||
if(res) {
|
||||
printf("RSA decrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ static const uint8_t elf_ident[] = {
|
|||
|
||||
// Turn PHDRs into flasher segments, checking for PHDR sanity and merging adjacent
|
||||
// unaligned segments if needed
|
||||
static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, int num_phdrs)
|
||||
static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, uint16_t num_phdrs)
|
||||
{
|
||||
Elf32_Phdr *phdr = phdrs;
|
||||
flash_seg_t *seg;
|
||||
|
@ -191,7 +191,7 @@ int flash_load(flash_file_t *ctx, const char *name, bool can_write_bl)
|
|||
FILE *fd = NULL;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr *phdrs = NULL;
|
||||
int num_phdrs;
|
||||
uint16_t num_phdrs;
|
||||
int res;
|
||||
|
||||
fd = fopen(name, "rb");
|
||||
|
@ -270,7 +270,7 @@ fail:
|
|||
// Get the state of the proxmark, backwards compatible
|
||||
static int get_proxmark_state(uint32_t *state)
|
||||
{
|
||||
UsbCommand c;
|
||||
UsbCommand c = {0};
|
||||
c.cmd = CMD_DEVICE_INFO;
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
|
|
|
@ -108,7 +108,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
|
|||
|
||||
for(uint16_t j = 0; j < num_infiles; j++) {
|
||||
for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
|
||||
c = fgetc(infile[j]);
|
||||
c = (uint8_t)fgetc(infile[j]);
|
||||
if (!feof(infile[j])) {
|
||||
fpga_config[i++] = c;
|
||||
} else if (num_infiles > 1) {
|
||||
|
|
|
@ -328,7 +328,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
|
|||
struct Crypto1State *p1, *p2, *p3, *p4;
|
||||
|
||||
// flush queue
|
||||
WaitForResponseTimeout(CMD_ACK, NULL, 100);
|
||||
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
UsbCommand c = {CMD_MIFARE_NESTED, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, calibrate}};
|
||||
memcpy(c.d.asBytes, key, 6);
|
||||
|
@ -910,6 +910,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint8_t parity, bool wantSaveToEml
|
|||
uint32_t nr1 = crypto1_word(pcs, nr_enc, 1) ^ nr_enc;
|
||||
uint32_t ar1 = crypto1_word(pcs, 0, 0) ^ ar_enc;
|
||||
uint32_t at1 = crypto1_word(pcs, 0, 0) ^ at_enc;
|
||||
crypto1_destroy(pcs);
|
||||
printf("key> the same key test. nr1: %08x ar1: %08x at1: %08x \n", nr1, ar1, at1);
|
||||
|
||||
if (NTParityCheck(nt1))
|
||||
|
|
|
@ -62,12 +62,9 @@ extern "C" void MainGraphics(void)
|
|||
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool usb_present)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
bool useGUI = getenv("DISPLAY") != 0;
|
||||
#else
|
||||
bool useGUI = true;
|
||||
#endif
|
||||
if (!useGUI)
|
||||
if (getenv("DISPLAY") == NULL)
|
||||
return;
|
||||
#endif
|
||||
|
||||
main_loop_thread = new WorkerThread(script_cmds_file, script_cmd, usb_present);
|
||||
gui = new ProxGuiQT(argc, argv, main_loop_thread);
|
||||
|
|
|
@ -110,7 +110,6 @@ class ProxGuiQT : public QObject
|
|||
ProxWidget *plotwidget;
|
||||
int argc;
|
||||
char **argv;
|
||||
void (*main_func)(void);
|
||||
WorkerThread *proxmarkThread;
|
||||
|
||||
public:
|
||||
|
|
|
@ -221,7 +221,7 @@ static int l_iso14443b_crc(lua_State *L)
|
|||
unsigned char buf[USB_CMD_DATA_SIZE];
|
||||
size_t len = 0;
|
||||
const char *data = luaL_checklstring(L, 1, &len);
|
||||
if (USB_CMD_DATA_SIZE < len)
|
||||
if (len > USB_CMD_DATA_SIZE-2)
|
||||
len = USB_CMD_DATA_SIZE-2;
|
||||
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
|
|
|
@ -117,7 +117,7 @@ uint64_t msclock() {
|
|||
#include <sys/timeb.h>
|
||||
struct _timeb t;
|
||||
_ftime(&t);
|
||||
return 1000 * t.time + t.millitm;
|
||||
return 1000 * (uint64_t)t.time + t.millitm;
|
||||
|
||||
// NORMAL CODE (use _ftime_s)
|
||||
//struct _timeb t;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue