From: pwpiwi Date: Thu, 23 Feb 2017 08:40:12 +0000 (+0100) Subject: Code cleanup: X-Git-Tag: v3.0.0~67 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/4c16ae80f0bffae2092e208c46a5005356c24ce1?ds=inline Code cleanup: - correctly using stdtypes.h printf and scanf format string macros (PRIx64 et al) - coverity fixes to client/cmdhfmf.c - fix linker warning re missing entry point when linking fullimage.elf --- diff --git a/armsrc/Makefile b/armsrc/Makefile index 0b540b84..04ae7a13 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -100,7 +100,7 @@ $(OBJDIR)/fullimage.data.o: $(OBJDIR)/fullimage.data.bin.z $(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=compressed_data $^ $@ $(OBJDIR)/fullimage.elf: $(OBJDIR)/fullimage.nodata.o $(OBJDIR)/fullimage.data.o - $(CC) $(LDFLAGS) -Wl,-T,ldscript,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ + $(CC) $(LDFLAGS) -Wl,-T,ldscript,-e,_osimage_entry,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ tarbin: $(OBJS) $(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(OBJS:%=armsrc/%) $(OBJS:%.s19=armsrc/%.elf) diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index d79b29fe..6a072bf4 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -340,7 +340,7 @@ static void hitag2_handle_reader_command(byte_t* rx, const size_t rxlen, byte_t* // Unknown command default: - Dbprintf("Uknown command: %02x %02x",rx[0],rx[1]); + Dbprintf("Unknown command: %02x %02x",rx[0],rx[1]); return; break; } @@ -1450,6 +1450,6 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) { AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); //Dbprintf("frame received: %d",frame_count); - //DbpString("All done"); - cmd_send(CMD_ACK,bSuccessful,0,0,(byte_t*)tag.sectors,48); + //DbpString("All done"); + cmd_send(CMD_ACK,bSuccessful,0,0,(byte_t*)tag.sectors,48); } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 54c5fc87..3fc3f8f7 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -35,8 +35,10 @@ int CmdHF14AMifare(const char *Cmd) SendCommand(&c); //flush queue - while (ukbhit()) getchar(); - + while (ukbhit()) { + int c = getchar(); (void) c; + } + // wait cycle while (true) { printf("."); @@ -303,7 +305,8 @@ int CmdHF14AMfDump(const char *Cmd) // Read keys A from file for (sectorNo=0; sectorNo FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4; + if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5; fnameptr += len; @@ -1547,7 +1554,7 @@ int CmdHF14AMfESave(const char *Cmd) len = param_getstr(Cmd,nameParamNo,filename); - if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4; + if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5; // user supplied filename? if (len < 1) { @@ -1823,7 +1830,7 @@ int CmdHF14AMfCLoad(const char *Cmd) return 0; } else { len = strlen(Cmd); - if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4; + if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5; memcpy(filename, Cmd, len); fnameptr += len; @@ -1864,6 +1871,7 @@ int CmdHF14AMfCLoad(const char *Cmd) if (mfCSetBlock(blockNum, buf8, NULL, 0, flags)) { PrintAndLog("Can't set magic card block: %d", blockNum); + fclose(f); return 3; } blockNum++; @@ -1992,7 +2000,7 @@ int CmdHF14AMfCSave(const char *Cmd) { return 0; } else { len = strlen(Cmd); - if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4; + if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5; if (len < 1) { // get filename @@ -2112,11 +2120,14 @@ int CmdHF14AMfSniff(const char *Cmd){ uint16_t traceLen = resp.arg[1]; len = resp.arg[2]; - if (res == 0) return 0; // we are done + if (res == 0) { // we are done + free(buf); + return 0; + } if (res == 1) { // there is (more) data to be transferred if (pckNum == 0) { // first packet, (re)allocate necessary buffer - if (traceLen > bufsize) { + if (traceLen > bufsize || buf == NULL) { uint8_t *p; if (buf == NULL) { // not yet allocated p = malloc(traceLen); diff --git a/client/cmdlfti.c b/client/cmdlfti.c index ba6a36bb..5dae9c0e 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -274,7 +274,7 @@ int CmdTIWrite(const char *Cmd) UsbCommand c = {CMD_WRITE_TI_TYPE}; int res = 0; - res = sscanf(Cmd, "%012" PRIx64 " %012" PRIx64 " %012" PRIx64 "", &c.arg[0], &c.arg[1], &c.arg[2]); + res = sscanf(Cmd, "%012" SCNx64 " %012" SCNx64 " %012" SCNx64 "", &c.arg[0], &c.arg[1], &c.arg[2]); if (res == 2) c.arg[2]=0; if (res < 2) diff --git a/tools/mfkey/mfkey32.c b/tools/mfkey/mfkey32.c index 0e64a3e8..44fee4a2 100755 --- a/tools/mfkey/mfkey32.c +++ b/tools/mfkey/mfkey32.c @@ -1,9 +1,4 @@ -#define __STDC_FORMAT_MACROS #include -#define llx PRIx64 -#define lli PRIi64 - -// Test-file: test2.c #include "crapto1.h" #include #include @@ -62,7 +57,7 @@ int main (int argc, char *argv[]) { crypto1_word(t, uid ^ nt, 0); crypto1_word(t, nr1_enc, 1); if (ar1_enc == (crypto1_word(t, 0, 0) ^ prng_successor(nt, 64))) { - printf("\nFound Key: [%012"llx"]\n\n",key); + printf("\nFound Key: [%012" PRIx64 "]\n\n",key); break; } } diff --git a/tools/mfkey/mfkey64.c b/tools/mfkey/mfkey64.c index 43e077e5..e7eb9dbe 100755 --- a/tools/mfkey/mfkey64.c +++ b/tools/mfkey/mfkey64.c @@ -1,9 +1,4 @@ -#define __STDC_FORMAT_MACROS #include -#define llx PRIx64 -#define lli PRIi64 - -// Test-file: test2.c #include "crapto1.h" #include #include @@ -103,7 +98,7 @@ int main (int argc, char *argv[]) { lfsr_rollback_word(revstate, nr_enc, 1); lfsr_rollback_word(revstate, uid ^ nt, 0); crypto1_get_lfsr(revstate, &key); - printf("\nFound Key: [%012"llx"]\n\n",key); + printf("\nFound Key: [%012" PRIx64"]\n\n",key); crypto1_destroy(revstate); return 0; diff --git a/tools/nonce2key/nonce2key.c b/tools/nonce2key/nonce2key.c index 32ea0a68..cc22ce77 100644 --- a/tools/nonce2key/nonce2key.c +++ b/tools/nonce2key/nonce2key.c @@ -1,7 +1,5 @@ #include "crapto1.h" -#define __STDC_FORMAT_MACROS #include -#define llx PRIx64 #include typedef unsigned char byte_t; @@ -20,13 +18,13 @@ int main(const int argc, const char* argv[]) { } sscanf(argv[1],"%08x",&uid); sscanf(argv[2],"%08x",&nt); - sscanf(argv[3],"%016"llx,&par_info); - sscanf(argv[4],"%016"llx,&ks_info); + sscanf(argv[3],"%016" SCNx64,&par_info); + sscanf(argv[4],"%016" SCNx64,&ks_info); // Reset the last three significant bits of the reader nonce nr &= 0xffffff1f; - printf("\nuid(%08x) nt(%08x) par(%016"llx") ks(%016"llx")\n\n",uid,nt,par_info,ks_info); + printf("\nuid(%08x) nt(%08x) par(%016" PRIx64 ") ks(%016" PRIx64 ")\n\n",uid,nt,par_info,ks_info); for (pos=0; pos<8; pos++) { @@ -52,7 +50,7 @@ int main(const int argc, const char* argv[]) { state = lfsr_common_prefix(nr,rr,ks3x,par); lfsr_rollback_word(state,uid^nt,0); crypto1_get_lfsr(state,&key_recovered); - printf("\nkey recovered: %012"llx"\n\n",key_recovered); + printf("\nkey recovered: %012" PRIx64 "\n\n",key_recovered); crypto1_destroy(state); return 0;