diff --git a/client/cmdhflist.c b/client/cmdhflist.c index 19bfa5100..e622a78ef 100644 --- a/client/cmdhflist.c +++ b/client/cmdhflist.c @@ -779,8 +779,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); diff --git a/client/cmdhfmfdes.c b/client/cmdhfmfdes.c index 8bdae2e04..0bf5b2443 100644 --- a/client/cmdhfmfdes.c +++ b/client/cmdhfmfdes.c @@ -271,13 +271,11 @@ void GetKeySettings( uint8_t *aid){ char *str = messStr; uint8_t isOK = 0; uint32_t options = NONE; - UsbCommand c; + UsbCommand c = {CMD_MIFARE_DESFIRE}; UsbCommand resp; //memset(messStr, 0x00, 512); - c.cmd = CMD_MIFARE_DESFIRE; - if ( aid == NULL ){ PrintAndLogEx(NORMAL, " CMK - PICC, Card Master Key settings "); PrintAndLogEx(NORMAL, ""); diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index 45def7b07..c35664a7f 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -267,7 +267,6 @@ static void init_bitflip_bitarrays(void) if (bytesread != filesize) { PrintAndLogEx(WARNING, "File read error with %s. Aborting...\n", state_file_name); fclose(statesfile); - inflateEnd(&compressed_stream); exit(5); } fclose(statesfile); diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 74771363f..7c8ce064a 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -2322,7 +2322,7 @@ int CmdHF14AMfucSetPwd(const char *Cmd){ // int CmdHF14AMfucSetUid(const char *Cmd){ - UsbCommand c; + UsbCommand c = {CMD_MIFAREU_READBL}; UsbCommand resp; uint8_t uid[7] = {0x00}; char cmdp = param_getchar(Cmd, 0); @@ -2335,7 +2335,6 @@ int CmdHF14AMfucSetUid(const char *Cmd){ } // read block2. - c.cmd = CMD_MIFAREU_READBL; c.arg[0] = 2; clearCommandBuffer(); SendCommand(&c); diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index 69567a3cb..3d3768f8b 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -255,7 +255,7 @@ int CmdHIDClone(const char *Cmd) { uint32_t hi2 = 0, hi = 0, lo = 0; uint32_t n = 0, i = 0; - UsbCommand c; + UsbCommand c = {CMD_HID_CLONE_TAG); uint8_t ctmp = param_getchar(Cmd, 0); if ( strlen(Cmd) == 0 || ctmp == 'H' || ctmp == 'h' ) return usage_lf_hid_clone(); @@ -280,7 +280,6 @@ int CmdHIDClone(const char *Cmd) { c.d.asBytes[0] = 0; } - c.cmd = CMD_HID_CLONE_TAG; c.arg[0] = hi2; c.arg[1] = hi; c.arg[2] = lo; diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index c969bc4da..ed2250a0c 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -182,8 +182,8 @@ int CmdLFHitagSim(const char *Cmd) { return 1; } tag_mem_supplied = true; - size_t bytes_read = fread(c.d.asBytes, 48, 1, f); - if ( bytes_read == 0) { + size_t bytes_read = fread(c.d.asBytes, 1, 48, f); + if ( bytes_read == 48) { PrintAndLogEx(WARNING, "Error: File reading error"); fclose(f); return 1; @@ -306,8 +306,8 @@ int CmdLFHitagSimS(const char *Cmd) { return 1; } tag_mem_supplied = true; - size_t bytes_read = fread(c.d.asBytes, 4*64, 1, f); - if ( bytes_read == 0) { + size_t bytes_read = fread(c.d.asBytes, 1, 4*64, f); + if ( bytes_read == 4*64) { PrintAndLogEx(WARNING, "Error: File reading error"); fclose(f); return 1; @@ -341,8 +341,8 @@ int CmdLFHitagCheckChallenges(const char *Cmd) { return 1; } file_given = true; - size_t bytes_read = fread(c.d.asBytes, 8*60, 1, f); - if ( bytes_read == 0) { + size_t bytes_read = fread(c.d.asBytes, 1, 8*60, f); + if ( bytes_read == 8*60) { PrintAndLogEx(WARNING, "Error: File reading error"); fclose(f); return 1; diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index ad6bf9c5a..6f6eb4f37 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -419,7 +419,7 @@ int CmdIndalaSim(const char *Cmd) { // iceman - needs refactoring int CmdIndalaClone(const char *Cmd) { - UsbCommand c; + UsbCommand c = {0}; uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7; uid1 = uid2 = uid3 = uid4 = uid5 = uid6 = uid7 = 0; uint32_t n = 0, i = 0; diff --git a/client/emv/crypto_polarssl.c b/client/emv/crypto_polarssl.c index 48e2ee4b1..cf68b40ea 100644 --- a/client/emv/crypto_polarssl.c +++ b/client/emv/crypto_polarssl.c @@ -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; } @@ -214,8 +216,9 @@ static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, co } res = rsa_public(&cp->ctx, buf, result); - if(res) { + if (res) { printf("RSA encrypt failed. Error: %x data len: %zu key len: %zu\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: %zu key len: %zu\n", res * -1, len, keylen); + free(result); return NULL; } diff --git a/client/fpga_compress.c b/client/fpga_compress.c index d7caff69a..26a2c2945 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -107,7 +107,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) { diff --git a/client/hid-flasher/flash.c b/client/hid-flasher/flash.c index c7ce3c8a3..e74f4ed49 100644 --- a/client/hid-flasher/flash.c +++ b/client/hid-flasher/flash.c @@ -264,10 +264,8 @@ fail: // Get the state of the proxmark, backwards compatible static int get_proxmark_state(uint32_t *state) { - UsbCommand c; - c.cmd = CMD_DEVICE_INFO; + UsbCommand c = {CMD_DEVICE_INFO}; SendCommand(&c); - UsbCommand resp; ReceiveCommand(&resp); diff --git a/client/proxgui.cpp b/client/proxgui.cpp index fefba9c50..3815579f4 100644 --- a/client/proxgui.cpp +++ b/client/proxgui.cpp @@ -62,13 +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); } diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 5cc41ba5d..f01526178 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -113,7 +113,7 @@ class ProxGuiQT : public QObject ProxWidget *plotwidget; int argc; char **argv; - void (*main_func)(void); + //void (*main_func)(void); WorkerThread *proxmarkThread; public: diff --git a/client/util_posix.c b/client/util_posix.c index e3198ffd5..7704e9d4b 100644 --- a/client/util_posix.c +++ b/client/util_posix.c @@ -118,7 +118,7 @@ uint64_t msclock(void) { #include 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;